# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
281841 |
2020-08-23T14:31:52 Z |
doowey |
Candies (JOI18_candies) |
C++14 |
|
729 ms |
27556 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)2e5 + 10;
ll f[N];
int main(){
fastIO;
int n;
cin >> n;
set<int> idx;
set<pii> vals;
for(int i = 1; i <= n; i ++ ){
cin >> f[i];
idx.insert(i);
vals.insert(mp(f[i], i));
}
ll sum = 0;
int id;
bool keep;
for(int i = 0 ; i < (n + 1) / 2; i ++ ){
auto it = vals.end();
-- it;
sum += it->fi;
cout << sum << "\n";
id = it->se;
vals.erase(it);
idx.erase(id);
f[id]=-f[id];
auto ri = idx.lower_bound(id+1);
auto li = idx.lower_bound(id);
keep = true;
if(li == idx.begin()){
keep = false;
}
else{
li -- ;
f[id] += f[*li];
vals.erase(mp(f[*li], *li));
idx.erase(li);
}
if(ri == idx.end()){
keep = false;
}
else{
f[id] += f[*ri];
vals.erase(mp(f[*ri], *ri));
idx.erase(ri);
}
if(keep){
vals.insert(mp(f[id], id));
idx.insert(id);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
3 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
640 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
3 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
640 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
684 ms |
27336 KB |
Output is correct |
22 |
Correct |
709 ms |
27232 KB |
Output is correct |
23 |
Correct |
729 ms |
27248 KB |
Output is correct |
24 |
Correct |
299 ms |
27096 KB |
Output is correct |
25 |
Correct |
314 ms |
27256 KB |
Output is correct |
26 |
Correct |
299 ms |
27256 KB |
Output is correct |
27 |
Correct |
314 ms |
27440 KB |
Output is correct |
28 |
Correct |
299 ms |
27384 KB |
Output is correct |
29 |
Correct |
292 ms |
27384 KB |
Output is correct |
30 |
Correct |
306 ms |
27332 KB |
Output is correct |
31 |
Correct |
305 ms |
27256 KB |
Output is correct |
32 |
Correct |
306 ms |
27256 KB |
Output is correct |
33 |
Correct |
447 ms |
27000 KB |
Output is correct |
34 |
Correct |
458 ms |
27128 KB |
Output is correct |
35 |
Correct |
448 ms |
27152 KB |
Output is correct |
36 |
Correct |
625 ms |
27268 KB |
Output is correct |
37 |
Correct |
679 ms |
27556 KB |
Output is correct |
38 |
Correct |
706 ms |
27256 KB |
Output is correct |
39 |
Correct |
266 ms |
27128 KB |
Output is correct |
40 |
Correct |
280 ms |
27128 KB |
Output is correct |
41 |
Correct |
282 ms |
27128 KB |
Output is correct |
42 |
Correct |
281 ms |
27256 KB |
Output is correct |
43 |
Correct |
283 ms |
27356 KB |
Output is correct |
44 |
Correct |
288 ms |
27256 KB |
Output is correct |
45 |
Correct |
315 ms |
27384 KB |
Output is correct |
46 |
Correct |
316 ms |
27284 KB |
Output is correct |
47 |
Correct |
298 ms |
27256 KB |
Output is correct |
48 |
Correct |
425 ms |
27096 KB |
Output is correct |
49 |
Correct |
435 ms |
27032 KB |
Output is correct |
50 |
Correct |
445 ms |
27080 KB |
Output is correct |