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>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
//#define int long long
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 2e5+777;
const int MOD = 1e9+7;
const bool I = 1;
int n, pref[N], k;
int get(int l, int r){
return pref[r] - (l - 1 < 0 ? 0 : pref[l-1]);
}
signed main(){
cin >> n >> k;
if(n > 10) {
cout << 0;
return false;
}
vector<int> a(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
if(!i) pref[i] = a[i];
else pref[i] = pref[i-1] + a[i];
}
// cerr << "pref\n";
// for(int i = 0; i < n; ++i){
// cerr << pref[i] << ' ';
// }cerr << '\n';
int res = 0;
vector<int> q;
for(int mask = 0; mask < (1 << n); ++mask){
vector<int> r;
for(int a = 0; a < n; ++a){
if((mask >> a) & 1){
r.push_back(a);
}
}
if(sz(r) != k) continue;
int last = 0, ans = 0;
for(int i = 0; i < sz(r); ++i){
ans += get(last, r[i]) * get(r[i] + 1, n-1);
last = r[i] + 1;
}
if(ans >= res){
res = ans;
q = r;
}
// for(auto it : r) cerr << it + 1 << ' '; cerr << ans << '\n';
}
cout << res << '\n';
for(auto it : q){
cout << it + 1 << ' ';
}
}
/*
7 3
4 1 3 4 0 2 3
*/
# | 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... |