80分!!!!!求助神犇!!!
查看原帖
80分!!!!!求助神犇!!!
527243
Iamzzr楼主2021/9/19 09:31
using namespace std;
const int M=100005;
int n, m, p1, p2, s1, s2;
long long ans=0, x=1e11;
int d=0, t=0;
int p[M], s[M], hand[M];
int main(){
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>p[i];
	cin>>m>>p1>>s1>>s2;
	p[p1]+=s1;
	
	for(int i=1; i<=n; i++)
		s[i]=abs(m-i);
		
	int ans=0, x=1e9;
	int d=0, t=0;
	for(int j=1; j<m; j++)
		d+=p[j]*s[j];
	for(int j=m+1; j<=n; j++)
		t+=p[j]*s[j];
		
	for(int i=1; i<=n; i++)
		hand[i]=s2*s[i];
	
	for(int i=1; i<=n; i++){
		if(i<m) d+=hand[i];
		else t+=hand[i];
		if(abs(d-t)<x){
			x=abs(d-t);
			ans=i;
		} 
		if(i<m) d-=hand[i];
		else t-=hand[i];
	} 
	cout<<ans;
	return 0; 
} 
2021/9/19 09:31
加载中...