#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=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);
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;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |