#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000006
typedef long long lld;
int N;
int A[MAXN];
lld D[MAXN], Nu[MAXN], S[MAXN];
int main()
{
scanf("%d", &N);
for (int i=1;i<=N;i++) scanf("%d", A+i);
for (int i=1;i<=N;i++) Nu[i] = Nu[i-1] + (lld)i * A[i], S[i] = S[i-1] + A[i];
lld ans = 0;
for (int i=1;i<=N;i++){
D[i] = D[i-1];
for (int j=0;j<i;j++){
D[i] = max(D[i], D[j] - Nu[j] + S[j] * j - S[i] * j + Nu[i]);
}
ans = max(ans, D[i]);
}
printf("%lld\n", ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
29064 KB |
Output is correct |
2 |
Correct |
0 ms |
29064 KB |
Output is correct |
3 |
Correct |
3 ms |
29064 KB |
Output is correct |
4 |
Correct |
0 ms |
29064 KB |
Output is correct |
5 |
Correct |
3 ms |
29064 KB |
Output is correct |
6 |
Correct |
2 ms |
29064 KB |
Output is correct |
7 |
Correct |
2 ms |
29064 KB |
Output is correct |
8 |
Correct |
0 ms |
29064 KB |
Output is correct |
9 |
Correct |
0 ms |
29064 KB |
Output is correct |
10 |
Correct |
0 ms |
29064 KB |
Output is correct |
11 |
Correct |
0 ms |
29064 KB |
Output is correct |
12 |
Correct |
0 ms |
29064 KB |
Output is correct |
13 |
Correct |
0 ms |
29064 KB |
Output is correct |
14 |
Correct |
2 ms |
29064 KB |
Output is correct |
15 |
Correct |
0 ms |
29064 KB |
Output is correct |
16 |
Correct |
0 ms |
29064 KB |
Output is correct |
17 |
Correct |
3 ms |
29064 KB |
Output is correct |
18 |
Correct |
0 ms |
29064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
29060 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |