이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |