#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1024;
const long long INF = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int n, a[N];
long long dp[N][N];
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = -INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i-1][0];
for (int j = 1; j <= i; j++) {
dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + (long long)j * a[i]);
}
}
long long ans = 0;
for (int j = 1; j <= n; j++) {
ans = max(ans, dp[n][j]);
}
printf("%lld\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
9280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |