Submission #654962

# Submission time Handle Problem Language Result Execution time Memory
654962 2022-11-02T08:55:41 Z onlk97 Candies (JOI18_candies) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	long long a[n+2];
	a[0]=a[n+1]=-1e18;
	for (int i=1; i<=n; i++) cin>>a[i];
	long long l[n+1],r[n+1];
	for (int i=1; i<=n; i++){
		l[i]=i-1;
		r[i]=i+1;
	}
	l[0]=0; r[n+1]=n+1;
	bool used[n+2];
	for (int i=0; i<=n+1; i++) used[i]=0;
	set <pair <long long,int>,greater <pair <long long,int> > > s;
	for (int i=1; i<=n; i++) s.insert(make_pair(a[i],i));
	long long ans=0;
	for (int iters=1; iters<=(n+1)/2; iters++){
		die:;
		pair <long long,int> tp=*s.begin(); s.erase(s.begin());
		if (used[tp.second]) goto die;
		ans+=tp.first;
		cout<<ans<<'\n';
		int ll=l[tp.second],rr=r[tp.second];
		a[tp.second]=a[ll]+a[rr]-a[tp.second];
		l[tp.second]=l[ll];
		r[tp.second]=r[rr];
		used[ll]=1;
      	used[rr]=1;
		r[l[tp.second]]=tp.second;
		l[r[tp.second]]=tp.second;
		if (ll>=1&&rr<=n) s.insert(make_pair(a[tp.second],tp.second));
	}
}

Compilation message

cc1plus: error: '::main' must return 'int'