Submission #58162

# Submission time Handle Problem Language Result Execution time Memory
58162 2018-07-17T04:43:35 Z 김세빈(#1689) Candies (JOI18_candies) C++11
100 / 100
1125 ms 29788 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

set <pll> S, P;
ll n, ans;

int main()
{
	ll i, a, k, f;
	pll p, s, s_p, s_n;
	
	scanf("%lld", &n);
	
	for(i=0;i<n;i++){
		scanf("%lld", &a);
		S.insert(pll(i, a));
		P.insert(pll(-a, i));
	}
	
	for(i=0;i+i<n;i++){
		p = *P.begin(); ans -= p.first;
		s = pll(p.second, -p.first);
		k = -s.second;
		f = 0;
		
		auto it = S.lower_bound(s);
		if(it != S.begin()){
			auto it_p = it; it_p --;
			s_p = *it_p;
			k += s_p.second;
			
			S.erase(s_p);
			P.erase(pll(-s_p.second, s_p.first));
		}
		else f = 1;
		
		it = S.lower_bound(s);
		{
			auto it_n = it; it_n ++;
			if(it_n != S.end()){
				s_n = *it_n;
				k += s_n.second;
				
				S.erase(s_n);
				P.erase(pll(-s_n.second, s_n.first));
			}
			else f = 1;
		}
		
		printf("%lld\n", ans);
		
		P.erase(p);
		S.erase(s);
		
		if(!f){
			S.insert(pll(s.first, k));
			P.insert(pll(-k, s.first));
		}
	}
	
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
candies.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 508 KB Output is correct
2 Correct 5 ms 660 KB Output is correct
3 Correct 4 ms 688 KB Output is correct
4 Correct 5 ms 688 KB Output is correct
5 Correct 5 ms 688 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 5 ms 772 KB Output is correct
8 Correct 5 ms 784 KB Output is correct
9 Correct 5 ms 804 KB Output is correct
10 Correct 4 ms 804 KB Output is correct
11 Correct 6 ms 804 KB Output is correct
12 Correct 7 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 4 ms 868 KB Output is correct
15 Correct 6 ms 1008 KB Output is correct
16 Correct 5 ms 1008 KB Output is correct
17 Correct 5 ms 1008 KB Output is correct
18 Correct 6 ms 1008 KB Output is correct
19 Correct 5 ms 1008 KB Output is correct
20 Correct 4 ms 1008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 508 KB Output is correct
2 Correct 5 ms 660 KB Output is correct
3 Correct 4 ms 688 KB Output is correct
4 Correct 5 ms 688 KB Output is correct
5 Correct 5 ms 688 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 5 ms 772 KB Output is correct
8 Correct 5 ms 784 KB Output is correct
9 Correct 5 ms 804 KB Output is correct
10 Correct 4 ms 804 KB Output is correct
11 Correct 6 ms 804 KB Output is correct
12 Correct 7 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 4 ms 868 KB Output is correct
15 Correct 6 ms 1008 KB Output is correct
16 Correct 5 ms 1008 KB Output is correct
17 Correct 5 ms 1008 KB Output is correct
18 Correct 6 ms 1008 KB Output is correct
19 Correct 5 ms 1008 KB Output is correct
20 Correct 4 ms 1008 KB Output is correct
21 Correct 889 ms 27224 KB Output is correct
22 Correct 914 ms 29244 KB Output is correct
23 Correct 1012 ms 29552 KB Output is correct
24 Correct 433 ms 29788 KB Output is correct
25 Correct 419 ms 29788 KB Output is correct
26 Correct 469 ms 29788 KB Output is correct
27 Correct 413 ms 29788 KB Output is correct
28 Correct 507 ms 29788 KB Output is correct
29 Correct 431 ms 29788 KB Output is correct
30 Correct 426 ms 29788 KB Output is correct
31 Correct 482 ms 29788 KB Output is correct
32 Correct 441 ms 29788 KB Output is correct
33 Correct 659 ms 29788 KB Output is correct
34 Correct 691 ms 29788 KB Output is correct
35 Correct 683 ms 29788 KB Output is correct
36 Correct 1071 ms 29788 KB Output is correct
37 Correct 983 ms 29788 KB Output is correct
38 Correct 1125 ms 29788 KB Output is correct
39 Correct 405 ms 29788 KB Output is correct
40 Correct 451 ms 29788 KB Output is correct
41 Correct 447 ms 29788 KB Output is correct
42 Correct 399 ms 29788 KB Output is correct
43 Correct 396 ms 29788 KB Output is correct
44 Correct 423 ms 29788 KB Output is correct
45 Correct 420 ms 29788 KB Output is correct
46 Correct 499 ms 29788 KB Output is correct
47 Correct 425 ms 29788 KB Output is correct
48 Correct 819 ms 29788 KB Output is correct
49 Correct 753 ms 29788 KB Output is correct
50 Correct 727 ms 29788 KB Output is correct