This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//gm --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NET r < tl || tr < l
#define double long double
using namespace std;
const int N=3e5+7;
const int M=1e9+7;
const int inf=1e18;
int a[N];
int mx;
vector <int> ans;
int n;
void rec(int l, int k, vector <int> v, int sum=0){
if(!k){
if(mx < sum){
mx = sum;
ans = v;
}
return;
}
int s=0;
for(int i=l; i <= n; i++){
s+=a[i];
}
int cur=0;
vector <int> f = v;
for(int i=l; i < n; i++){
cur += a[i];
f.pb(i);
rec(i+1, k-1, f, sum+(cur*(s-cur)));
f.erase(f.begin()+f.size()-1);
}
}
int k;
void emash(){
cin >> n >> k;
for(int i=1; i <= n; i++){
cin >> a[i];
}
vector <int> v;
rec(1, k, v);
cout << mx << '\n';
for(auto i : ans){
cout << i << ' ';
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("milkorder.in", "r", stdin);
// freopen("milkorder.out", "w", stdout);
int RealName=1;
// cin >> RealName;
while(RealName--){
//cout << "Case " << ++C << ":\n";
emash();
}
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... |