# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82929 | memetkagan44 | Split the sequence (APIO14_sequence) | C++11 | 12 ms | 976 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;
vector<int> v;
queue<pair<int,int> > q;
int n,k,a,top[100005];
long long ans;
int main(){
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a);
top[i]=top[i-1]+a;
}
q.push(make_pair(1,n));
while(!q.empty() && k>0){
int l=q.front().first,r=q.front().second;
q.pop();
if(l<r){
k--;
int i=l;
for(;top[i]-top[l-1]<=(top[r]-top[l-1])/2;i++);
if(abs((top[i-1]-top[l-1])-(top[r]-top[l-1])/2)<(top[i]-top[l-1])-(top[r]-top[l-1])/2)
i--;
ans+=(top[i]-top[l-1])*(top[r]-top[i]);
v.push_back(i);
q.push(make_pair(l,i));
q.push(make_pair(i+1,r));
}
}
printf("%lld\n",ans);
for(int i=0;i<v.size();i++){
printf("%d",v[i]);
if(i<v.size()-1)
printf(" ");
else
printf("\n");
}
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... |