Submission #285883

# Submission time Handle Problem Language Result Execution time Memory
285883 2020-08-29T17:20:08 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=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){
		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];
		bool add=0;
		if(l!=idx.begin()){
			add=1;
			l=prev(l);
			u[tmp.Y]+=u[*l];
			idx.erase(l);
			ms.erase(mp(u[*l],*l));
		}
		if(r!=idx.end()){
			add=1;
			u[tmp.Y]+=u[*r];
			idx.erase(r);
			ms.erase(mp(u[*r],*r));
		}
		if(add)ms.insert(mp(u[tmp.Y],tmp.Y)),idx.insert(tmp.Y);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -