Submission #914047

# Submission time Handle Problem Language Result Execution time Memory
914047 2024-01-20T23:42:52 Z amirhoseinfar1385 Candies (JOI18_candies) C++17
0 / 100
2 ms 600 KB
#include<bits/stdc++.h>
using namespace std;
long long inf=1e15;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n;
	cin>>n;
	vector<int>all(n);
	set<int>allind;
	set<pair<int,int>>st;
	for(long long i=0;i<n;i++){
		cin>>all[i];
		st.insert(make_pair(all[i],i));
		allind.insert(i);
	}
	long long res=0;
	while((int)allind.size()>0){
		auto x=*st.rbegin();
		st.erase(x);
		res+=x.first;
		cout<<res<<"\n";
		if((int)allind.size()==1){
			break;
		}
		if((*allind.begin())==x.second){
			allind.erase(*allind.begin());
			st.erase(make_pair(all[*allind.begin()],*allind.begin()));
			allind.erase(*allind.begin());
			continue;
		}
		if((*allind.rbegin())==x.second){
			allind.erase(*allind.rbegin());
			st.erase(make_pair(all[*allind.rbegin()],*allind.rbegin()));
			allind.erase(*allind.rbegin());
			continue;
		}
		allind.erase(x.second);
		auto y=allind.lower_bound(x.second);
		int nx=*y;
		y--;
		int ps=*y;
		st.erase(make_pair(all[nx],nx));
		st.erase(make_pair(all[ps],ps));
		allind.erase(nx);
		allind.erase(ps);
		all[x.second]=all[nx]+all[ps]-all[x.second];
		st.insert(make_pair(all[x.second],x.second));
		allind.insert(x.second);
	}

}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -