#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 998244353;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 222;
int a[N];
ll dp[M][M][M];
ll pref[N];
ll sum(int l, int r){
return pref[r] - pref[l - 1];
}
pair<ll, int> cost(int l, int r){
ll res = 0;
int ind = 0;
for (int i = l; i < r; i++){
ll cur = sum(l, i) * sum(i + 1, r);
if (cur > res){
res = cur;
ind = i;
}
}
return MP(res, ind);
}
void solve(int TC) {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
ll ans = 0;
priority_queue<pair<pair<ll, int>, pair<int, int>>> pq;
pq.push(MP(cost(1, n), MP(1, n)));
vector<int> ind;
while (k--){
auto top = pq.top();
ll cur = top.first.first;
int m = top.first.second;
int l = top.second.first, r = top.second.second;
ans += cur;
ind.push_back(m);
debug(cur, m, l, r);
pq.pop();
if (l < m) pq.push(MP(cost(l, m), MP(l, m)));
if (m + 1 < r) pq.push(MP(cost(m + 1, r), MP(m + 1, r)));
}
cout << ans << endl;
for (int i : ind) cout << i << ' ';
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
Compilation message
sequence.cpp: In function 'void solve(int)':
sequence.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
sequence.cpp:89:9: note: in expansion of macro 'debug'
89 | debug(cur, m, l, r);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Incorrect |
1 ms |
332 KB |
contestant didn't find the optimal answer: 951 < 999 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
contestant didn't find the optimal answer: 1093726 < 1093956 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
332 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
0 ms |
332 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
1 ms |
324 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Incorrect |
0 ms |
332 KB |
contestant didn't find the optimal answer: 1019625813 < 1019625819 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
contestant didn't find the optimal answer: 21419072 < 21503404 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
contestant didn't find the optimal answer: 1794250000 < 1818678304 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1612 KB |
contestant found the optimal answer: 19795776960 == 19795776960 |
2 |
Correct |
7 ms |
1612 KB |
contestant found the optimal answer: 19874432173 == 19874432173 |
3 |
Incorrect |
8 ms |
1996 KB |
contestant didn't find the optimal answer: 497009314607795353 < 497313449256899208 |
4 |
Halted |
0 ms |
0 KB |
- |