#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e16;
const int inf = 2e9;
ll in[200010],ans;
int n,l[200010],r[200010];
set<pll> SET;
int main(){
fastio;
cin>>n;
for(int i=1;i<=n;i++){
cin>>in[i];
SET.insert(pll(-in[i],i));
l[i]=i-1;r[i]=i+1;
}
r[0]=1;
l[n+1]=n;
for(int j=1;j<=(n+1)/2;j++){
pll t = pll(SET.begin()->fi, SET.begin()->se);
SET.erase(t);
ans -= t.fi;
int i = t.se;
in[i] = in[r[i]] + in[l[i]] - in[i];
SET.insert(pll(-in[i], i));
SET.erase(pll(-in[l[i]],l[i]));
SET.erase(pll(-in[r[i]],r[i]));
l[i] = l[l[i]];
r[i] = r[r[i]];
r[l[i]] = i;
l[r[i]] = i;
cout<<ans<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |