Submission #44343

# Submission time Handle Problem Language Result Execution time Memory
44343 2018-03-31T12:56:40 Z zadrga Candies (JOI18_candies) C++14
100 / 100
923 ms 29896 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll arr[maxn];
set<pair<ll, int> > s;
set<pair<int, ll> > ind;
vector<ll> ans;

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%lld", arr + i);
		s.insert(mp(-arr[i], i));
		ind.insert(mp(i, -arr[i]));
	}


	// we mustn't choose the ones at the ends since the number of candies stays the same

	ind.insert(mp(0, INF));		
	ind.insert(mp(n + 1, INF));
	s.insert(mp(INF, 0));
	s.insert(mp(INF, n + 1));

	ll cur = 0;

	for(int k = 0; k < (n + 1) / 2; k++){
		vector<pair<ll, int> > v;

		auto it = s.begin();
		cur = cur + (-it -> fi);
		ans.pb(cur);

		auto it1 = ind.lower_bound(mp(it -> se, -INF));
		it1--;

		auto it2 = ind.lower_bound(mp(it -> se, -INF)); 
		it2++;

		v.pb(*it);
		v.pb(mp(it1 -> se, it1 -> fi));
		v.pb(mp(it2 -> se, it2 -> fi));
		
		int pos = it -> se;
		ll tren = it1 -> se + it2 -> se - it -> fi;

		for(auto i : v){
			s.erase(mp(i.fi, i.se));
			ind.erase(mp(i.se, i.fi));
		}

		s.insert(mp(tren, pos));
		ind.insert(mp(pos, tren));
	}

	for(ll i : ans)
		printf("%lld\n", i);
		
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
candies.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", arr + i);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 828 KB Output is correct
4 Correct 4 ms 828 KB Output is correct
5 Correct 5 ms 884 KB Output is correct
6 Correct 5 ms 884 KB Output is correct
7 Correct 6 ms 884 KB Output is correct
8 Correct 5 ms 884 KB Output is correct
9 Correct 4 ms 884 KB Output is correct
10 Correct 4 ms 884 KB Output is correct
11 Correct 5 ms 884 KB Output is correct
12 Correct 5 ms 884 KB Output is correct
13 Correct 4 ms 884 KB Output is correct
14 Correct 6 ms 940 KB Output is correct
15 Correct 5 ms 940 KB Output is correct
16 Correct 4 ms 1032 KB Output is correct
17 Correct 5 ms 1032 KB Output is correct
18 Correct 5 ms 1032 KB Output is correct
19 Correct 4 ms 1032 KB Output is correct
20 Correct 5 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 828 KB Output is correct
4 Correct 4 ms 828 KB Output is correct
5 Correct 5 ms 884 KB Output is correct
6 Correct 5 ms 884 KB Output is correct
7 Correct 6 ms 884 KB Output is correct
8 Correct 5 ms 884 KB Output is correct
9 Correct 4 ms 884 KB Output is correct
10 Correct 4 ms 884 KB Output is correct
11 Correct 5 ms 884 KB Output is correct
12 Correct 5 ms 884 KB Output is correct
13 Correct 4 ms 884 KB Output is correct
14 Correct 6 ms 940 KB Output is correct
15 Correct 5 ms 940 KB Output is correct
16 Correct 4 ms 1032 KB Output is correct
17 Correct 5 ms 1032 KB Output is correct
18 Correct 5 ms 1032 KB Output is correct
19 Correct 4 ms 1032 KB Output is correct
20 Correct 5 ms 1068 KB Output is correct
21 Correct 923 ms 29640 KB Output is correct
22 Correct 844 ms 29724 KB Output is correct
23 Correct 868 ms 29740 KB Output is correct
24 Correct 413 ms 29820 KB Output is correct
25 Correct 405 ms 29820 KB Output is correct
26 Correct 401 ms 29820 KB Output is correct
27 Correct 421 ms 29820 KB Output is correct
28 Correct 428 ms 29820 KB Output is correct
29 Correct 472 ms 29852 KB Output is correct
30 Correct 454 ms 29852 KB Output is correct
31 Correct 472 ms 29852 KB Output is correct
32 Correct 455 ms 29852 KB Output is correct
33 Correct 609 ms 29852 KB Output is correct
34 Correct 653 ms 29852 KB Output is correct
35 Correct 618 ms 29852 KB Output is correct
36 Correct 838 ms 29896 KB Output is correct
37 Correct 843 ms 29896 KB Output is correct
38 Correct 885 ms 29896 KB Output is correct
39 Correct 400 ms 29896 KB Output is correct
40 Correct 423 ms 29896 KB Output is correct
41 Correct 403 ms 29896 KB Output is correct
42 Correct 445 ms 29896 KB Output is correct
43 Correct 421 ms 29896 KB Output is correct
44 Correct 428 ms 29896 KB Output is correct
45 Correct 571 ms 29896 KB Output is correct
46 Correct 564 ms 29896 KB Output is correct
47 Correct 566 ms 29896 KB Output is correct
48 Correct 645 ms 29896 KB Output is correct
49 Correct 636 ms 29896 KB Output is correct
50 Correct 628 ms 29896 KB Output is correct