답안 #285893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285893 2020-08-29T17:38:06 Z YJU Candies (JOI18_candies) C++14
0 / 100
4 ms 512 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=2e5+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,greater<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){
		pll tmp=*ms.begin();ms.erase(ms.begin());
		ans+=tmp.X;
		cout<<ans<<"\n";
		if(i==(n+1)/2)break;
		ll l=(idx.lwb(tmp.Y)==idx.begin()?0:*prev(idx.lwb(tmp.Y)));
		ll r=(idx.lwb(tmp.Y+1)==idx.end()?0:*idx.lwb(tmp.Y+1));
		u[tmp.Y]=-tmp.X+u[l]+u[r];
		ms.erase(mp(u[l],l));ms.erase(mp(u[r],r));
		idx.erase(l);idx.erase(r);
		ms.insert(mp(u[tmp.Y],tmp.Y));
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -