답안 #700911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700911 2023-02-19T12:02:50 Z urosk Candies (JOI18_candies) C++14
0 / 100
1 ms 468 KB
#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;
        if(l!=1&&r!=n+1) pq.push({b[r+1]-b[l-1]-2*x,{l-1,r+1}});
        else if(l==1) pq.push({b[r+1]-b[l]-2*x,{l,r+1}});
        else if(r==n+1) pq.push({b[r]-b[l-1]-2*x,{l-1,r}});
        cnt++;
        cout<<ans<<endl;
    }
    if((n&1)&&cnt!=(n+1)/2){
        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
**/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -