#include<stdio.h>
#include<queue>
double max(double a, double b) {
if (a > b) {
return a;
}
return b;
}
double arr[1001];
double dy[1001][1001];
int check[1001][1001];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lf", &arr[i]);
}
check[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (check[i - 1][j]) {
if (check[i][j + 1]) {
dy[i][j + 1] = max(dy[i][j + 1], dy[i - 1][j] + (arr[i] * (j + 1)));
}
else {
dy[i][j + 1] = dy[i - 1][j] + (arr[i] * (j + 1));
check[i][j + 1] = 1;
}
if (check[i][0]) {
dy[i][0] = max(dy[i][0], dy[i - 1][j]);
}
else {
dy[i][0] = dy[i - 1][j];
check[i][0] = 1;
}
}
else {
break;
}
}
}
double ans = 0;
for (int i = 0; i <= n; i++) {
if (check[n][i]) {
ans = max(ans, dy[n][i]);
}
}
printf("%.0lf", ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12832 KB |
Output is correct |
2 |
Correct |
5 ms |
12832 KB |
Output is correct |
3 |
Correct |
5 ms |
12832 KB |
Output is correct |
4 |
Correct |
0 ms |
12832 KB |
Output is correct |
5 |
Correct |
5 ms |
12832 KB |
Output is correct |
6 |
Correct |
5 ms |
12832 KB |
Output is correct |
7 |
Correct |
5 ms |
12832 KB |
Output is correct |
8 |
Correct |
5 ms |
12832 KB |
Output is correct |
9 |
Correct |
5 ms |
12832 KB |
Output is correct |
10 |
Correct |
0 ms |
12832 KB |
Output is correct |
11 |
Correct |
0 ms |
12832 KB |
Output is correct |
12 |
Correct |
5 ms |
12832 KB |
Output is correct |
13 |
Correct |
5 ms |
12832 KB |
Output is correct |
14 |
Correct |
5 ms |
12832 KB |
Output is correct |
15 |
Correct |
0 ms |
12832 KB |
Output is correct |
16 |
Correct |
0 ms |
12832 KB |
Output is correct |
17 |
Correct |
0 ms |
12832 KB |
Output is correct |
18 |
Correct |
0 ms |
12832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
12828 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |