没过样例但是AC了
查看原帖
没过样例但是AC了
1164775
Jadonyzx楼主2024/5/6 14:30

赛时莫名AC了

#include<bits/stdc++.h>

#define int long long

using namespace std;

inline int read(){

	int x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){

		if(ch=='-')f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();

	return x*f;

}

inline void write(int x){

	if(x<0){

		putchar('-');

		write(-x);

		return;

	}

	if(x>=10)write(x/10);

	putchar(x%10+'0');

	return;

}

int n,p,q,r,ans,a[100010],sum,pr[100010],czr;

signed main(){

	bool f=0;

	n=read();p=read();q=read();r=read();

	for(int i=0;i<n;++i)a[i]=read(),sum+=a[i];

	sort(a,a+n);

	if(sum>=0){

		cout<<0;

		return 0;

	}

	if(n==1){

		ans=-p*a[0];

		cout<<ans;

		return 0;

	}

	czr=0;

	for(int i=0;i<n;++i){

		if(a[i]<0){

			if(q<=-p*a[i]){

				ans+=q;

				czr++;

				sum-=a[i];

				if(sum>=0){

					if(czr==n){

						ans-=q;

						ans+=-a[n-1]*p;

						cout<<ans;

						return 0;

					}

					cout<<ans;

					return 0;

				}

			}

			else{

				ans+=-sum*p;

				cout<<ans;

				return 0;

			}

		}

	}

	return 0;

}
2024/5/6 14:30
加载中...