Submission #700907

#TimeUsernameProblemLanguageResultExecution timeMemory
700907uroskCandies (JOI18_candies)C++14
0 / 100
1 ms468 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include "bits/stdc++.h" //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; #define maxn 200005 ll n; ll a[maxn],b[maxn]; bool ok[maxn]; void tc(){ cin >> n; for(ll i = 1;i<=n;i++) cin >> a[i]; for(ll i = 2;i<=n+1;i++) b[i] = b[i-1] + a[i-1]; priority_queue<pair<ll,pll> > pq; for(ll i = 1;i<=n;i++) pq.push({b[i+1]-b[i],{i,i+1}}); ll cnt = 0,ans = 0; while(sz(pq)&&cnt<(n+1)/2){ pair<ll,pll> p = pq.top(); pq.pop(); ll l = p.sc.fi,r = p.sc.sc,x = p.fi; if(ok[l]||ok[r]) continue; ok[l] = 1,ok[r] = 1; ans+=x; pq.push({b[r+1]-b[l-1]-2*x,{l-1,r+1}}); if(l<r) ok[l+1] = ok[r-1] = 0; cnt++; cout<<ans<<endl; } if(n&1){ ans = 0; for(ll i = 1;i<=n;i+=2) ans+=a[i]; cout<<ans<<endl; } } int main(){ daj_mi_malo_vremena int t; t = 1; while(t--){ tc(); } return 0; } /** 5 3 5 1 7 6 20 623239331 125587558 908010226 866053126 389255266 859393857 596640443 60521559 11284043 930138174 936349374 810093502 521142682 918991183 743833745 739411636 276010057 577098544 551216812 816623724 **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...