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;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 2e5;
int pre[nax];
int main(){
int n,k;
cin>>n>>k;
vector<int> a(n),c;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++){
pre[i] = a[i];
if(i)pre[i] += pre[i-1];
}
ll ans = 0;
vector<int> cur;
cur.push_back(n);
for(int i=0;i<k;i++){
ll mx = 0;
int id = 0,at = 0,q = 0,b = 0;
int lf = 0,ri = 0;
for(int j=0;j<n-1;j++){
if(q == cur[id] - 1){
q = 0;
id++;
}else{
ll pf = 0;
if(j-q-1 >= 0)pf = pre[j-q-1];
ll points = (pre[j] - pf) * (pre[j-q+cur[id]-1] - pre[j]);
if(points > mx){
mx = points;
at = j;
b = id;
lf = cur[id] - q - 1;
ri = cur[id] - lf;
}
q++;
}
}
ans += mx;
cur.erase(cur.begin() + b);
cur.insert(cur.begin() + b,lf);
cur.insert(cur.begin() + b,ri);
c.push_back(at);
}
cout << ans << endl;
// sort(c.begin(),c.end());
for(int i : c)
cout << i+1 << ' ';
printf("\n");
}
# | 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... |