Submission #855947

#TimeUsernameProblemLanguageResultExecution timeMemory
8559478pete8Candies (JOI18_candies)C++14
100 / 100
80 ms12508 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include<bitset> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); using namespace std; #define int long long const int mxn=2*1e5,mod=29947,lg=25,inf=1e18; int l[mxn+10],r[mxn+10]; bitset<mxn+10>del; int32_t main(){ fastio int n;cin>>n; vector<int>v(n+2); priority_queue<pii>pq; for(int i=1;i<=n;i++)cin>>v[i],pq.push({v[i],i}),l[i]=i-1,r[i]=i+1; int ans=0; v[0]=v[n+1]=-inf; for(int i=1;i<=(n+1)/2;i++){ while(del[pq.top().s])pq.pop(); ans+=pq.top().f; int cur=pq.top().s; cout<<ans<<'\n'; pq.pop(); del[l[cur]]=true; del[r[cur]]=true; v[cur]=v[l[cur]]+v[r[cur]]-v[cur]; pq.push({v[cur],cur}); l[cur]=l[l[cur]]; r[cur]=r[r[cur]]; r[l[cur]]=cur; l[r[cur]]=cur; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...