Submission #197565

#TimeUsernameProblemLanguageResultExecution timeMemory
197565NeklixxSplit the sequence (APIO14_sequence)C++14
0 / 100
316 ms3184 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define F first #define S second #define all(v) v.begin(), v.end() #define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); #define FILE freopen("test.in", "r", stdin); #define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";} #define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;} #define debug cout << "-----------------------------------------------" << endl; #define print1(a) cout << "{ " << a << " }" << endl; #define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl; #define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl; #define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl; using namespace std; #define int long long const int INF = 1e18 + 228; const int MAXN = 1e5 + 228; bool used[MAXN]; signed main() { #ifdef LOCAL FILE; #endif sh; int n, k; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) { int aa; cin >> aa; v.pb(aa); } vector<int> p; p.pb(0); for (int i = 0; i < n; i++) { p.pb(p[i] + v[i]); } vector<int> b; b.pb(0); b.pb(n - 1); int ans = 0; vector<int> kek; for (int _ = 0; _ < k; _++) { int mx = -INF; int pos = 0; for (int i = 1; i < n; i++) { if (used[i]) continue; int r = lower_bound(all(b), i) - b.begin(); int l = r - 1; int lef = p[i] - p[b[l]]; int rig = p[b[r] + 1] - p[i]; if (mx < lef * rig) { mx = lef * rig; pos = i; } } ans += mx; used[pos] = 1; b.pb(pos - 1); b.pb(pos); sort(all(b)); kek.pb(pos); } cout << ans << endl; for (auto to : kek) { cout << to << ' '; } 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...