This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |