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
using namespace std;
ll n,k,i,a[101],b[11],sum[101],s,ans=-1;
vector<ll> v;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
for(i=1;i<=n;i++){
cin >> a[i];
sum[i]=sum[i-1]+a[i];
}
for(i=1;i<n;i++) b[i]=i;
b[0]=n;
do{
s=0;
for(i=1;i<=k;i++){
if(b[i]<b[i+1] && i<k){
s=-1;
break;
}
s+=(sum[b[i]]*(sum[b[i-1]]-sum[b[i]]));
}
if(s>ans){
ans=s;
v.clear();
for(i=1;i<=k;i++) v.push_back(b[i]);
}
}while(next_permutation(b+1,b+n));
cout << ans << "\n";
for(i=0;i<k;i++) cout << v[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... |