Submission #745283

#TimeUsernameProblemLanguageResultExecution timeMemory
745283maks007Split the sequence (APIO14_sequence)C++14
0 / 100
553 ms2400 KiB
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> order_set; #define int long long signed main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); order_set S; int n, k; cin >> n >> k; vector <int> a(n); for(auto &i : a) cin >> i; int pref[n]; function <int(int,int)> get=[&](int l, int r) { if(l == 0) return pref[r]; return pref[r] - pref[l - 1]; }; function <int(int)> Sum=[&](int pos) { auto pered = S.upper_bound(pos); auto zad = --S.upper_bound(pos); int sumPered = get(pos + 1, *pered); int sumZad = get(*zad+1, pos); return sumPered * sumZad; }; pref[0] = a[0]; for(int i = 1; i < n; i ++) pref[i] = a[i] + pref[i-1]; S.insert(-1); S.insert(n-1); set <int> ans; vector <int> res; int sum = 0; for(int step = 0; step < k; step ++) { int mx = -LLONG_MAX, pos; for(int i = 0; i < n-1; i ++) { if(ans.count(i) == 1) continue; if(Sum(i) > mx) { mx = Sum(i); pos = i; } // cout << i << " " << Sum(i) << "\n"; } // cout << "\n"; sum += mx; ans.insert(pos); res.push_back(pos); S.insert(pos); } cout << sum << "\n"; for(auto i : res) cout << i+1 << " "; return 0; } /* 7 3 4 1 3 4 0 2 3 */
#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...