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 <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#define debug(format, ...) printf(format, __VA_ARGS__);
const int N_ = 1000500;
int N;
ll A[N_];
ll S1[N_], S2[N_];
ll cost (int l, int r) {
return (S2[r] - S2[l-1]) - (S1[r] - S1[l-1]) * (l-1);
}
struct line {
ll a, b;
line (ll a = 0, ll b = 0): a(a), b(b) { }
ll y (ll x) { return a * x + b; }
};
struct CHT {
vector<line> stk;
void add (line p) {
}
} cht;
ll tb[N_];
int main() {
scanf("%d", &N);
for(int i = 1; i <= N; i++) {
scanf("%lld", A+i);
S1[i] = S1[i-1] + A[i];
S2[i] = S2[i-1] + i * A[i];
}
for(int i = 1; i <= N; i++) {
tb[i] = tb[i-1];
for(int j = 0; j < i; j++) {
ll val = tb[j] + S2[i]
- (S1[i]) * j
+ (-S2[j] + S1[j] * j);
tb[i] = max(tb[i], val);
}
}
printf("%lld\n", tb[N]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |