# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1071416 |
2024-08-23T07:15:04 Z |
phong |
Candies (JOI18_candies) |
C++17 |
|
335 ms |
33360 KB |
#include<bits/stdc++.h>
#define ll long long
#define int long long
const int nmax = 3e5 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;
int n, a[nmax];
int ans[nmax];
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i];
multiset<pii> one, two;
a[0] = -oo;
a[n + 1] = -oo;
for(int i = 0; i <= n + 1; ++i){
one.insert({a[i], i});
two.insert({i, a[i]});
}
for(int i = 1; i <= (n + 1) / 2; ++i){
auto x = *one.rbegin();
ans[i] = ans[i - 1] + x.fi;
cout << ans[i] << endl;
// if(i == (n + 1) / 2) continue;
auto it = two.lower_bound({x.se, -oo});
--it;
pii s1 = *it;
one.erase(one.find({s1.se, s1.fi}));
two.erase(it++);
pii s2 = *it;
one.erase(one.find({s2.se, s2.fi}));
two.erase(it++);
pii s3 = *it;
one.erase(one.find({s3.se, s3.fi}));
two.erase(it++);
one.insert({s1.se + s3.se - s2.se, s2.fi});
two.insert({s2.fi, s1.se + s3.se - s2.se});
}
}
/*
*/
Compilation message
candies.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2780 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2700 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2780 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2700 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
21 |
Correct |
335 ms |
33084 KB |
Output is correct |
22 |
Correct |
329 ms |
33096 KB |
Output is correct |
23 |
Correct |
320 ms |
32948 KB |
Output is correct |
24 |
Correct |
160 ms |
32968 KB |
Output is correct |
25 |
Correct |
155 ms |
32888 KB |
Output is correct |
26 |
Correct |
186 ms |
32856 KB |
Output is correct |
27 |
Correct |
183 ms |
33104 KB |
Output is correct |
28 |
Correct |
185 ms |
33104 KB |
Output is correct |
29 |
Correct |
192 ms |
33108 KB |
Output is correct |
30 |
Correct |
171 ms |
33080 KB |
Output is correct |
31 |
Correct |
165 ms |
33092 KB |
Output is correct |
32 |
Correct |
179 ms |
33108 KB |
Output is correct |
33 |
Correct |
242 ms |
32880 KB |
Output is correct |
34 |
Correct |
258 ms |
32808 KB |
Output is correct |
35 |
Correct |
252 ms |
32812 KB |
Output is correct |
36 |
Correct |
315 ms |
33084 KB |
Output is correct |
37 |
Correct |
313 ms |
33360 KB |
Output is correct |
38 |
Correct |
319 ms |
33100 KB |
Output is correct |
39 |
Correct |
155 ms |
32848 KB |
Output is correct |
40 |
Correct |
157 ms |
32820 KB |
Output is correct |
41 |
Correct |
165 ms |
32836 KB |
Output is correct |
42 |
Correct |
201 ms |
33080 KB |
Output is correct |
43 |
Correct |
172 ms |
33088 KB |
Output is correct |
44 |
Correct |
169 ms |
33020 KB |
Output is correct |
45 |
Correct |
182 ms |
33104 KB |
Output is correct |
46 |
Correct |
174 ms |
33196 KB |
Output is correct |
47 |
Correct |
202 ms |
33136 KB |
Output is correct |
48 |
Correct |
237 ms |
32956 KB |
Output is correct |
49 |
Correct |
259 ms |
32848 KB |
Output is correct |
50 |
Correct |
264 ms |
32848 KB |
Output is correct |