# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
565492 |
2022-05-21T01:36:34 Z |
lohacho |
Candies (JOI18_candies) |
C++14 |
|
824 ms |
42944 KB |
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
multiset<vector<int>> st1, st2;
for(int i = 0; i < n; ++i){
st1.insert({i, a[i], 1});
st2.insert({a[i], i, 1});
}
int cnt = 0, sum = 0;
multiset<vector<int>>::iterator sv;
int dosv = 0;
while(cnt < (n + 1) / 2){
auto p2 = prev(st2.end());
if(dosv){
dosv = 0;
p2 = sv;
}
while(p2 != st2.begin() && (*p2)[2] == 0 && (*p2)[0] < 0){
--p2;
}
int nowi = (*p2)[1];
cnt += (*p2)[2], sum += (*p2)[0];
if((*p2)[2] > 0){
cout << sum << endl;
}
int dcnt = -(*p2)[2], dsum = -(*p2)[0];
auto p1 = st1.lower_bound(vector<int>{nowi, -(int)1e18, -(int)1e18});
if(p1 != st1.begin()){
auto p1p = prev(p1);
dsum += (*p1p)[1];
dcnt += (*p1p)[2];
st2.erase(st2.find(vector<int>{(*p1p)[1], (*p1p)[0], (*p1p)[2]}));
st1.erase(p1p);
}
auto p1n = next(p1);
if(p1n != st1.end()){
dsum += (*p1n)[1];
dcnt += (*p1n)[2];
st2.erase(st2.find(vector<int>{(*p1n)[1], (*p1n)[0], (*p1n)[2]}));
st1.erase(p1n);
}
st2.insert({dsum, nowi, dcnt});
st1.insert({nowi, dsum, dcnt});
if(dcnt == 0 && dsum >= 0){
dosv = 1;
sv = st2.find(vector<int>{dsum, nowi, dcnt});
}
st2.erase(p2);
st1.erase(p1);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
720 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
736 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
720 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
736 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
775 ms |
42872 KB |
Output is correct |
22 |
Correct |
780 ms |
42856 KB |
Output is correct |
23 |
Correct |
824 ms |
42832 KB |
Output is correct |
24 |
Correct |
415 ms |
42700 KB |
Output is correct |
25 |
Correct |
410 ms |
42704 KB |
Output is correct |
26 |
Correct |
405 ms |
42636 KB |
Output is correct |
27 |
Correct |
415 ms |
42876 KB |
Output is correct |
28 |
Correct |
421 ms |
42804 KB |
Output is correct |
29 |
Correct |
407 ms |
42812 KB |
Output is correct |
30 |
Correct |
433 ms |
42864 KB |
Output is correct |
31 |
Correct |
426 ms |
42792 KB |
Output is correct |
32 |
Correct |
428 ms |
42800 KB |
Output is correct |
33 |
Correct |
556 ms |
42652 KB |
Output is correct |
34 |
Correct |
561 ms |
42592 KB |
Output is correct |
35 |
Correct |
556 ms |
42804 KB |
Output is correct |
36 |
Correct |
768 ms |
42776 KB |
Output is correct |
37 |
Correct |
805 ms |
42860 KB |
Output is correct |
38 |
Correct |
761 ms |
42940 KB |
Output is correct |
39 |
Correct |
416 ms |
42716 KB |
Output is correct |
40 |
Correct |
411 ms |
42700 KB |
Output is correct |
41 |
Correct |
411 ms |
42772 KB |
Output is correct |
42 |
Correct |
419 ms |
42772 KB |
Output is correct |
43 |
Correct |
413 ms |
42824 KB |
Output is correct |
44 |
Correct |
407 ms |
42780 KB |
Output is correct |
45 |
Correct |
429 ms |
42860 KB |
Output is correct |
46 |
Correct |
433 ms |
42944 KB |
Output is correct |
47 |
Correct |
440 ms |
42876 KB |
Output is correct |
48 |
Correct |
571 ms |
42636 KB |
Output is correct |
49 |
Correct |
556 ms |
42716 KB |
Output is correct |
50 |
Correct |
565 ms |
42612 KB |
Output is correct |