Codeforces 429D Tricky Function
This is equivalent to I representing the X axis, sum [I] representing the Y axis, sum [I] representing the sum of the previous I numbers
Calculate the distance between the minimum two points.
The so-called question is the question that suddenly becomes enlightened after reading the question, that is, the distance between j-> I first calculated during calculation,
# Include
# Include
# Include
Using namespace std; typedef long ll; # define N 11111ll a [N]; ll sum [N]; int ans; int main () {int n; sum [0] = 0; scanf ("% d", & n); for (int I = 1; I <= n; I ++) {scanf ("I64d", & a [I]); sum [I] = sum [I-1] + a [I];} ans = a [2] * a [2] + 1; for (ll I = 1; I
Ans) break; // so importantll t = ans; for (int j = I + 1; j <= n; j ++) {t = min (t, (sum [j]-sum [j-I]) * (sum [j]-sum [j-I]);} ans = min (ans, t + I * I);} cout <