I. Inquiry I_数组


I. Inquiry I_数组_02

题意:

给定数组 I. Inquiry I_数组_03, 求公式的最大值。
I. Inquiry I_数组_03

AC代码:

const int N = 1e6 + 10;
int n, m;
ll ans, res, tmp, cnt;
int a[N];

int main()
{
sd(n);
ll sum1 = 0;
ll sum2 = 0;
rep(i, 1, n)
sd(a[i]),
sum1 += a[i];
ans = 0;
rep(i, 1, n)
{
sum2 += a[i] * a[i];
sum1-=a[i];
ans = max(ans, sum1 * sum2);
}
pld(ans);
return 0;
}