Submission #770654

#TimeUsernameProblemLanguageResultExecution timeMemory
770654OrazBSplit the sequence (APIO14_sequence)C++17
0 / 100
11 ms2420 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //Dijkstra->set //set.find_by_order(x) x-position value //set.order_of_key(x) number of strictly less elements don't need *set.?? #define N 100005 #define wr cout << "Continue debugging\n"; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const ll INF = 1e18; int n, k; int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; vector<ll>a(n+1), pref(n+1, 0); for (int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i-1]+a[i]; } vector<int> vec; ll sum = 0; set<pii> s = {{1, n}}; while(k--){ ll mx = 0, l2 = 0, r2 = 0, idx = 0; for (auto z : s){ ll x = 0, y = 0, mn = INF; int l = z.ff, r = z.ss, pos = 0; while(l <= r){ int md = (l+r)/2; ll A = pref[md]-pref[z.ff-1], B = pref[z.ss]-pref[md]; if (mn > abs(A-B)){ mn = abs(A-B); x = A; y = B; pos = md; } (A>B ? r=md-1 : l=md+1); } if (mx < x*y){ mx = x*y; l2 = z.ff; r2 = z.ss; idx = pos; } } sum += mx; s.erase({l2, r2}); if (l2 != idx) s.insert({l2, idx}); if (r2 != idx) s.insert({idx+1, r2}); vec.pb(idx); } cout << sum << '\n'; for (auto i : vec) cout << i << " "; }
#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...