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 ll long long int
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define sz size()
const int N = 2e5 + 1;
using namespace std;
ll a[N], p[N], ans, n, k;
set <pii> s;
vector <int> v;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
p[i] = p[i-1] + a[i];
}
s.insert({1,n});
while(k--){
ll mx = 0;
int bol, poz, poz1;
for(auto i: s){
for(int j = i.ff; j < i.ss; j++){
ll san = p[j] - p[i.ff-1], san1 = p[i.ss] - p[j];
if(san * san1 >= mx){
mx = san * san1;
bol = j;
poz = i.ff;
poz1 = i.ss;
}
}
}
ans += mx;
s.erase({poz,poz1});
s.insert({poz,bol});
s.insert({bol+1,poz1});
v.pb(bol);
}
cout << ans << '\n';
for(auto i : v) cout << i << ' ';
}
# | 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... |