This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* \`*-.
* ) _`-.
* . : `. .
* : _ ' \
* ; *` _. `*-._
* `-.-' `-.
* ; ` `.
* :. . \
* . \ . : .-' .
* ' `+.; ; ' :
* : ' | ; ;-.
* ; ' : :`-: _.`* ;
* [VĐ] .*' / .*' ; .*`- +' `*'
* `*-* `*-* `*-*'
**/
/** HELLO WOLRD**/
#include <bits/stdc++.h>
#define NAME "main"
#define data DANG
#define int int64_t
#define ii pair<int64_t , int64_t>
#define fi first
#define se second
using namespace std;
const int64_t INF64 = 0x3f3f3f3f3f3f3f3f;
const int INF32 = 0x3f3f3f3f;
const int N = 2e5;
int n , k;
int64_t a[N + 2] , pre[N + 2];
int64_t ans , sum , tmp , res;
void init(){
cin >> n >> k;
for(int i = 1 ; i <= n ; i++)
cin >> a[i];
}
void solve(){
for(int i = 1 ; i <= n ; i++)
pre[i] = pre[i - 1] + a[i];
for(int i = 1 ; i < (1 << n) ; i++){
sum = 0 , tmp = 0;
int x = __builtin_popcount(i);
if(x != k) continue;
for(int j = 0 ; j < n ; j++){
if(i >> j & 1){
sum += (pre[n] - pre[j + 1]) * (pre[j + 1] - tmp);
tmp = pre[j + 1];
}
}
if(sum > ans){
ans = sum;
res = i;
}
}
cout << ans << '\n';
for(int i = 0 ; i < n ; i++)
if(res >> i & 1) cout << i + 1 << " ";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
init();
solve();
}
# | 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... |