-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc.c
More file actions
32 lines (29 loc) · 722 Bytes
/
Copy pathicpc.c
File metadata and controls
32 lines (29 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
int main() {
long long t;
scanf("%lld", &t);
while(t--) {
long long n;
scanf("%lld", &n);
long long a[n+1], x, sum = 0;
a[0] = 0;
for (long long i = 1; i <= n; i++)
{
scanf("%lld", &x);
a[i] = a[i - 1] + x;
sum += x;
}
long long ans = 0;
long long xx = 0;
for (long long r = 1; r <= n; r++)
{
long long j = (r * r) + r - a[r];
long long w = r + a[r-1] - (r * r);
if (w > xx)xx = w;
long long gain = xx + j;
if (gain > ans)ans = gain;
}
printf("%lld\n", sum + ans);
}
return 0;
}