제출 #724205

#제출 시각아이디문제언어결과실행 시간메모리
724205colossal_pepe수열 (APIO14_sequence)C++17
0 / 100
7 ms1800 KiB
#include <iostream> #include <tuple> #include <vector> #include <queue> using namespace std; using ll = long long; using seq = tuple<ll, int, int, int>; const int N = 1e5; int n, k; ll a[N + 5], pfx_sum[N + 5]; seq eval(int L, int R) { if (L == R) return make_tuple(0, L, R, L); int l = L, r = R; while (r - l > 1) { int m = (l + r) / 2; if (2 * pfx_sum[m] <= pfx_sum[R] - pfx_sum[L - 1]) l = m + 1; else r = m; } if (2 * (pfx_sum[l] - pfx_sum[L - 1]) <= pfx_sum[R] - pfx_sum[L - 1]) l++; r = l; l--; ll x1 = (pfx_sum[l] - pfx_sum[L - 1]) * (pfx_sum[R] - pfx_sum[l]); ll x2 = (pfx_sum[r] - pfx_sum[L - 1]) * (pfx_sum[R] - pfx_sum[r]); if (x1 < x2) return make_tuple(x2, L, R, r); else return make_tuple(x1, L, R, l); } pair<ll, vector<int>> solve() { priority_queue<seq> q; q.push(eval(1, n)); pair<ll, vector<int>> ret = {0, vector<int>(0)}; while (k--) { auto [score, l, r, m] = q.top(); q.pop(); ret.first += score; ret.second.push_back(m); q.push(eval(l, m)); q.push(eval(m + 1, r)); } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; pfx_sum[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; pfx_sum[i] = a[i] + pfx_sum[i - 1]; } pair<ll, vector<int>> ans = solve(); cout << ans.first << '\n'; for (int i : ans.second) { cout << i << ' '; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...