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>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,k,p[N],s[N],ans;
vector<int> v;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k;
for (int i=1;i<=n;i++) cin>>a[i];
for (int t=1;t<=k;t++){
for (int i=1;i<=n;i++){
p[i]=a[i];
if (b[i-1]==b[i]) p[i]+=p[i-1];
}
for (int i=n;i;i--){
s[i]=a[i];
if (b[i+1]==b[i] && i<n) s[i]+=s[i+1];
}
//for (int i=1;i<=n;i++) cout<<p[i]<<' ';cout<<endl;
int best,mx=-1;
for (int i=1;i<n;i++){
if (b[i+1]!=b[i]) continue;
if (p[i]*s[i+1]>=mx) mx=p[i]*s[i+1],best=i;
}
v.pb(best);
ans+=mx;
for (int i=best+1;b[i]==b[best] && i<=n;i++) b[i]=t;
}
cout<<ans<<endl;
for (auto u:v) cout<<u<<' ';
return 0;
}
# | 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... |