# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546729 | krit3379 | Split the sequence (APIO14_sequence) | C++17 | 2095 ms | 85072 KiB |
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<bits/stdc++.h>
using namespace std;
#define N 100005
struct line{
long long m,c;
int i;
long long val(long long x){return m*x+c;}
long long inter(line l){return floor((long double)(c-l.c)/(l.m-m));}
};
long long a[N],ans;
int p[N][205],now;
vector<int> cut;
deque<line> dq[205];
int main(){
int n,k,i,j;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
dq[0].push_back({0,0,0});
for(i=1;i<=n;i++){
for(j=k;j>0;j--){
if(dq[j-1].empty())continue;
while(dq[j-1].size()>=2&&dq[j-1].back().val(a[n]-a[i])<=dq[j-1][dq[j-1].size()-2].val(a[n]-a[i]))dq[j-1].pop_back();
long long v=dq[j-1].back().val(a[n]-a[i])+a[i]*(a[n]-a[i]);
if(v>=ans)ans=v,now=i;
p[i][j]=dq[j-1].back().i;
line l={-a[i],v,i};
while(dq[j].size()>=2&&dq[j][0].inter(dq[j][1])<=dq[j][0].inter(l))dq[j].pop_front();
dq[j].push_front(l);
}
}
while(now){
cut.push_back(now);
now=p[now][k--];
}
printf("%lld\n",ans);
for(auto x:cut)printf("%d ",x);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |