# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919690 | Aiperiii | Split the sequence (APIO14_sequence) | C++14 | 77 ms | 9248 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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
bool ok[500000];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,k;
cin>>n>>k;
vector <int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
vector <vector <int> > v;
vector <int> ids;
for(int i=0;i<n;i++){
ids.pb(i);
}
v.pb(ids);
vector <int> res;
int ans=0;
while(k--){
int mx=-10,div=0,ind=0;
for(int j=0;j<v.size();j++){
if(ok[j])continue;
vector <int> pr;
int sum=0;
for(int i=0;i<v[j].size();i++){
sum+=a[v[j][i]];
pr.pb(sum);
}
for(int i=0;i<pr.size();i++){
int x=pr.back()-pr[i];
if(mx<x*pr[i]){
mx=x*pr[i];
div=i;
ind=j;
}
}
}
ok[ind]=1;
vector <int> g1,g2;
res.pb(v[ind][div]);
for(int i=0;i<v[ind].size();i++){
if(i<=div)g1.pb(v[ind][i]);
else g2.pb(v[ind][i]);
}
v.pb(g1);v.pb(g2);
ans+=mx;
}
cout<<ans<<"\n";
for(auto x :res)cout<<x+1<<" ";
cout<<"\n";
}
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... |