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;
int n;
long long inp[N], A[N], dp[N];
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &inp[i]);
}
A[n-1] = inp[n-1];
for (int i = n-2; i >= 0; i--)
A[i] = A[i+1] + inp[i];
dp[0] = max(inp[0], 0ll);
for (int j = 1; j < n; j++) {
dp[j] = dp[j-1];
long long sum = 0;
for (int i = j; i >= 0; i--) {
sum += (long long)(A[i] - A[j+1]);
dp[j] = max(dp[j], dp[j-1] + sum);
}
}
long long ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, dp[i]);
printf("%lld\n", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |