Submission #970737

#TimeUsernameProblemLanguageResultExecution timeMemory
970737GangstaSplit the sequence (APIO14_sequence)C++14
0 / 100
5 ms2652 KiB
/* ID: didarco1 TASK: LANG: c++17 */ #include "bits/stdc++.h" #define ll long long int #define pb push_back #define pii pair<int,int> #define ff first #define ss second #define sz size() const int N = 2e5 + 1; using namespace std; ll a[N], p[N], ans, n, k; set <pii> s; vector <int> bol; vector <int> v; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; p[i] = p[i-1] + a[i]; } s.insert({1,n}); while(k--){ ll mx = 0; int bol, poz, poz1; for(auto i: s){ for(int j = i.ff; j < i.ss; j++){ ll san = p[j] - p[i.ff-1], san1 = p[i.ss] - p[j]; if(san * san1 >= mx){ mx = san * san1; bol = j; poz = i.ff; poz1 = i.ss; } } } ans += mx; s.erase({poz,poz1}); s.insert({poz,bol}); s.insert({bol+1,poz1}); v.pb(bol); } cout << ans << '\n'; for(auto i : v) 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...