이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)1e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, k, a[N], p[N];
void solve() {
cin >> n >> k;
for(int i = 0; i < n; ++i) {
cin >> a[i];
if(i) p[i] = p[i - 1];
p[i] += a[i];
}
int ans = 0, id = 0;
for(int mask = 0; mask < (1 << n); ++mask) {
int x = __builtin_popcount(mask);
if(x != k || (mask & (1 << (n - 1)))) continue;
int l = 0, cur = 0;
for(int i = 0; i < n; ++i) {
if(mask >> i & 1) {
cur += (p[i] - (l == 0 ? 0 : p[l - 1])) * (p[n-1] - p[i]);
l = i + 1;
}
}
if(cur > ans) {
ans = cur;
id = mask;
}
}
cout << ans << nl;
for(int i = 0; i < n; ++i) if(id >> i & 1) cout << i + 1 << ' ';
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
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... |