# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
285879 |
2020-08-29T17:17:22 Z |
YJU |
Candies (JOI18_candies) |
C++14 |
|
4 ms |
640 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=2e6+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
ll n,u[N],ans,vis[N];
multiset<pll> ms;
set<ll> idx;
int main(){
//ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
REP1(i,n)cin>>u[i],ms.insert(mp(u[i],i)),idx.insert(i);
REP1(i,(n+1)/2){
while(vis[prev(ms.end())->Y])ms.erase(prev(ms.end()));
pll tmp=*prev(ms.end());ms.erase(prev(ms.end()));
ans+=tmp.X;
cout<<ans<<"\n";
auto l=idx.lwb(tmp.Y),r=idx.lwb(tmp.Y+1);
u[tmp.Y]=-u[tmp.Y];
if(l!=idx.begin()){
l=prev(l);
u[tmp.Y]+=u[*l];
vis[*l]=1;
idx.erase(l);
}
if(r!=idx.end()){
u[tmp.Y]+=u[*r];
vis[*r]=1;
idx.erase(r);
}
ms.insert(mp(u[tmp.Y],tmp.Y));
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |