#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1e9, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
main () {
int n, m;
cin >> n >> m;
int a[ n + 1 ];
for ( int i = 0; i < n; i ++ ) {
cin >> a[ i ];
sum += a[ i ];
}
mn = sum;
ans = mx = 0;
mx = -oo;
for ( int mask = 0; mask < ( 1 << ( n - 1 ) ); mask ++ ) {
if ( __builtin_popcount( mask ) != m )
continue;
for ( int i = 0; i < n - 1; i ++ ) {
num += a[ i ];
sum -= a[ i ];
if ( mask & ( 1 << i ) ) {
ans += num * sum;
num = 0;
}
}
if ( mx < ans ) {
mx = ans;
pos = mask;
}
num = ans = 0;
sum = mn;
}
cout << mx << "\n";
for ( int i = 0; i < n - 1; i ++ ) {
if ( pos & ( 1 << i ) )
cout << i + 1 << " ";
}
}
/*
7 3
4 1 3 4 0 2 3
*/
Compilation message
sequence.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 4500000000 == 4500000000 |
6 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 1 == 1 |
7 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 1 == 1 |
8 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 1 == 1 |
9 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 100400096 == 100400096 |
10 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 900320000 == 900320000 |
11 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 3698080248 == 3698080248 |
12 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 3200320000 == 3200320000 |
13 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 140072 == 140072 |
14 |
Correct |
1 ms |
204 KB |
contestant found the optimal answer: 376041456 == 376041456 |
15 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 805 == 805 |
16 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 900189994 == 900189994 |
17 |
Correct |
0 ms |
204 KB |
contestant found the optimal answer: 999919994 == 999919994 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
declared answer doesn't correspond to the split scheme: declared = 1094706, real = 413262 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
declared answer doesn't correspond to the split scheme: declared = 613673465, real = 484112 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
declared answer doesn't correspond to the split scheme: declared = 22135291, real = 263998 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
332 KB |
declared answer doesn't correspond to the split scheme: declared = 2090982627, real = 1606920 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
1068 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |