Submission #237001

# Submission time Handle Problem Language Result Execution time Memory
237001 2020-06-04T08:08:55 Z kshitij_sodani Candies (JOI18_candies) C++17
100 / 100
851 ms 30700 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo n;
llo it[200001];
llo l[200001];
llo r[200001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	for(llo i=0;i<n-1;i++){
		r[i]=i+1;
	}
	r[n-1]=-1;
	l[0]=-1;
	for(llo i=1;i<n;i++){
		l[i]=i-1;
	}
	set<pair<llo,llo>> ss;
	set<llo> aa;
	for(llo i=0;i<n;i++){
		ss.insert({-it[i],i});
		aa.insert(i);
	}
	llo su=0;
	for(llo i=0;i<(n+1)/2;i++){
		pair<llo,llo> no=*(ss.begin());
		ss.erase(no);

		su+=-no.a;
		cout<<su<<endl;
		llo ind=no.b;
		llo su2=no.a;
		auto kk=aa.upper_bound(ind);
		auto ll=aa.lower_bound(ind);
	//	ll--;
		/*if(i+1==(n+1)/2){
			break;
		}*/
		if(kk!=aa.end() and ll!=aa.begin()){
			ll--;
		//	cout<<(*kk)<<","<<(*ll)<<endl;
			su2+=it[*kk];
			su2+=it[*ll];
		//	cout<<su2<<endl;
			it[ind]=su2;
		/*	if(ss.find({-it[*kk],*kk})==ss.end() or ss.find({-it[*ll],*ll})==ss.end()){
				cout<<11<<endl;
				cout<<it[*kk]<<"::"<<it[*ll]<<endl;
			}*/
		/*	if(ss.find({-it[*kk],*kk})==ss.end() or ss.find({-it[*ll],*ll})==ss.end()){
				while(true){
					continue;
				}
			}*/
				ss.erase({-it[*kk],*kk});
				aa.erase(*kk);
				ss.erase({-it[*ll],*ll});
				aa.erase(*ll);
			ss.insert({-su2,ind});
		}
		else{
			
			if(kk!=aa.end()){
			/*	if(ss.find({-it[*kk],*kk})==ss.end()){
					while(true)continue;
				}*/
				ss.erase({-it[*kk],*kk});
				aa.erase(*kk);
			}

			if(ll!=aa.begin()){
				ll--;
			/*	if(ss.find({-it[*ll],*ll})==ss.end()){
					while(true)continue;
				}*/
				ss.erase({-it[*ll],*ll});
				aa.erase(*ll);
			}
			aa.erase(ind);
		}
		/*for(auto j:ss){
			cout<<j.a<<"/"<<j.b<<endl;
		}
		cout<<endl;*/

	}


	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 640 KB Output is correct
2 Correct 9 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 9 ms 640 KB Output is correct
5 Correct 9 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 9 ms 640 KB Output is correct
13 Correct 10 ms 640 KB Output is correct
14 Correct 9 ms 640 KB Output is correct
15 Correct 8 ms 640 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 9 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 640 KB Output is correct
20 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 640 KB Output is correct
2 Correct 9 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 9 ms 640 KB Output is correct
5 Correct 9 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 9 ms 640 KB Output is correct
13 Correct 10 ms 640 KB Output is correct
14 Correct 9 ms 640 KB Output is correct
15 Correct 8 ms 640 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 9 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 640 KB Output is correct
20 Correct 8 ms 640 KB Output is correct
21 Correct 845 ms 30456 KB Output is correct
22 Correct 851 ms 30432 KB Output is correct
23 Correct 845 ms 30416 KB Output is correct
24 Correct 472 ms 30492 KB Output is correct
25 Correct 466 ms 30328 KB Output is correct
26 Correct 484 ms 30348 KB Output is correct
27 Correct 476 ms 30584 KB Output is correct
28 Correct 485 ms 30436 KB Output is correct
29 Correct 501 ms 30500 KB Output is correct
30 Correct 488 ms 30492 KB Output is correct
31 Correct 481 ms 30456 KB Output is correct
32 Correct 486 ms 30576 KB Output is correct
33 Correct 633 ms 30412 KB Output is correct
34 Correct 620 ms 30140 KB Output is correct
35 Correct 614 ms 30584 KB Output is correct
36 Correct 847 ms 30560 KB Output is correct
37 Correct 837 ms 30700 KB Output is correct
38 Correct 805 ms 30560 KB Output is correct
39 Correct 450 ms 30304 KB Output is correct
40 Correct 451 ms 30200 KB Output is correct
41 Correct 482 ms 30380 KB Output is correct
42 Correct 464 ms 30432 KB Output is correct
43 Correct 464 ms 30456 KB Output is correct
44 Correct 481 ms 30488 KB Output is correct
45 Correct 496 ms 30456 KB Output is correct
46 Correct 508 ms 30432 KB Output is correct
47 Correct 478 ms 30584 KB Output is correct
48 Correct 620 ms 30456 KB Output is correct
49 Correct 638 ms 30328 KB Output is correct
50 Correct 631 ms 30200 KB Output is correct