边界处理就是折磨王
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1000005;
int a[N];
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
long long m,s,p,q;
cin>>m>>s>>p>>q;
a[s]+=p;
long long sum=0;
for(int i=1;i<=n;i++)
sum+=(m-i)*a[i];
if(sum>0)
{
if(abs(sum-sum/q*q)>abs(sum-(sum/q+1)*q))
cout<<m+sum/q+1<<endl;
else
cout<<m+sum/q<<endl;
}
else
{
if(abs(sum-sum/q*q)>=abs(sum-(sum/q-1)*q))
cout<<m+sum/q-1<<endl;
else
cout<<m+sum/q<<endl;
}
return 0;
}