Ok...
Topic link: https: //www.luogu.org/problem/P5016
This question is a simulation, do not consider the complex, direct violence enumerate every point and see the difference after s2 plus two forces, looking for the smallest record label.
Note that data is large, a long long, the minimum initial value should be large enough.
AC Code:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 5 using namespace std; 6 7 long long n, p1, s1, s2, sum1, sum2, ans = 1e19, m, now, t1, t2, tmp; 8 long long c[10000005]; 9 10 int main(){ 11 scanf("%lld", &n); 12 for(int i = 1; i <= n; i++) scanf("%lld", &c[i]); 13 scanf("%lld%lld%lld%lld", &m, &p1, &s1, &s2); 14 c[p1] += s1; 15 for(int i = 1; i <= m - 1; i++) sum1 += c[i] * (m - i); 16 for(int i = m + 1; i <= n; i++) sum2 += c[i] * (i - m); 17 if(sum1 == sum2) {printf("%lld", m); return 0;} 18 for(int i = 1; i <= n; i++){ 19 t1 = sum1, t2 = sum2; 20 if(i < m) t1 += (m - i) * s2; 21 else t2 += (i - m) * s2; 22 tmp = abs(t1 - t2); 23 if(tmp < ans) {ans = tmp; now = i;} 24 } 25 printf("%lld", now); 26 return 0; 27 }