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<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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |