#include<stdio.h>
using namespace std;
long long map[1010][1010];
long long sco[1010];
int n;
void input() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &sco[i]);
}
}
void process() {
int i, j, k;
long long maxi;
for (j = 0; j < n; j++) {
for (i = 0; i <= j+1; i++) {
if (i == 0) {
if (j == 0){
map[i][j] = 0;
continue;
}
maxi = -1000000000000000000L;
for (k = 0; k <= j; k++) {
if (maxi < map[k][j - 1]) maxi = map[k][j - 1];
map[i][j] = maxi;
}
continue;
}
if (j == 0) map[i][j] = i*sco[j];
else {
map[i][j] = map[i - 1][j - 1] + i*sco[j];
}
}
}
maxi = -1000000000000000000L;
for (i = 0; i <= n; i++) if (maxi < map[i][n - 1]) maxi = map[i][n - 1];
printf("%lld\n", maxi);
}
int main() {
input();
process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9060 KB |
Output is correct |
2 |
Correct |
5 ms |
9060 KB |
Output is correct |
3 |
Correct |
5 ms |
9060 KB |
Output is correct |
4 |
Correct |
0 ms |
9060 KB |
Output is correct |
5 |
Correct |
5 ms |
9060 KB |
Output is correct |
6 |
Correct |
5 ms |
9060 KB |
Output is correct |
7 |
Correct |
5 ms |
9060 KB |
Output is correct |
8 |
Correct |
5 ms |
9060 KB |
Output is correct |
9 |
Correct |
2 ms |
9060 KB |
Output is correct |
10 |
Correct |
2 ms |
9060 KB |
Output is correct |
11 |
Correct |
5 ms |
9060 KB |
Output is correct |
12 |
Correct |
2 ms |
9060 KB |
Output is correct |
13 |
Correct |
5 ms |
9060 KB |
Output is correct |
14 |
Correct |
5 ms |
9060 KB |
Output is correct |
15 |
Correct |
2 ms |
9060 KB |
Output is correct |
16 |
Correct |
2 ms |
9060 KB |
Output is correct |
17 |
Correct |
0 ms |
9060 KB |
Output is correct |
18 |
Correct |
0 ms |
9060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
9056 KB |
Program hung waiting for input |
2 |
Halted |
0 ms |
0 KB |
- |