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<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[1000010],d[1000010],p[1000010],p2[1000010];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
p[i]=p[i-1]+a[i];
p2[i]=p2[i-1]+i*a[i];
}
for(int i=1;i<=n;i++){
d[i]=p2[i];
for(int j=1;j<i-1;j++){
d[i]=max(d[i],d[j]+(p2[i]-p2[j+1])-(j+1)*(p[i]-p[j+1]));
}
}
cout<<d[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |