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>
using namespace std;
long long map[1010][1010];
long long sco[1010];
int n;
void input() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &sco[i]);
}
}
void process() {
int i, j, k;
long long maxi;
for (j = 0; j < n; j++) {
for (i = 0; i <= j+1; i++) {
if (i == 0) {
if (j == 0){
map[i][j] = 0;
continue;
}
maxi = -1000000000000000000L;
for (k = 0; k <= j; k++) {
if (maxi < map[k][j - 1]) maxi = map[k][j - 1];
map[i][j] = maxi;
}
continue;
}
if (j == 0) map[i][j] = i*sco[j];
else {
map[i][j] = map[i - 1][j - 1] + i*sco[j];
}
}
}
maxi = -1000000000000000000L;
for (i = 0; i <= n; i++) if (maxi < map[i][n - 1]) maxi = map[i][n - 1];
printf("%lld\n", maxi);
}
int main() {
input();
process();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |