# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442230 | 2021-07-07T10:13:52 Z | cpp219 | Candies (JOI18_candies) | C++14 | 632 ms | 28916 KB |
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 3; const ll Log2 = 20; const ll inf = 1e16 + 7; typedef pair<ll,ll> LL; ll n,a[N],val[N]; set<LL> s; set<ll> num; int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin>>n; val[0] = val[n + 1] = -inf; num.insert(0); num.insert(n + 1); for (ll i = 1;i <= n;i++) cin>>a[i],s.insert({a[i],i}),val[i] = a[i],num.insert(i); ll cur = 0,p; for (ll i = 1;i <= (n + 1)/2;i++){ LL t = *s.rbegin(); s.erase(prev(s.end())); cur += t.fs; ll now = t.sc; num.erase(now); auto it1 = num.lower_bound(now),it2 = num.upper_bound(now); ll p = now,q = now; if (it1 != num.begin()) p = *prev(it1); if (it2 != num.end()) q = *it2; s.erase({val[p],p}); s.erase({val[q],q}); val[p] += val[q] - t.fs; num.erase(q); s.insert({val[p],p}); cout<<cur<<"\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 588 KB | Output is correct |
2 | Correct | 3 ms | 588 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 3 ms | 588 KB | Output is correct |
5 | Correct | 3 ms | 588 KB | Output is correct |
6 | Correct | 2 ms | 588 KB | Output is correct |
7 | Correct | 3 ms | 588 KB | Output is correct |
8 | Correct | 3 ms | 588 KB | Output is correct |
9 | Correct | 2 ms | 588 KB | Output is correct |
10 | Correct | 2 ms | 588 KB | Output is correct |
11 | Correct | 3 ms | 588 KB | Output is correct |
12 | Correct | 3 ms | 588 KB | Output is correct |
13 | Correct | 2 ms | 588 KB | Output is correct |
14 | Correct | 3 ms | 588 KB | Output is correct |
15 | Correct | 3 ms | 588 KB | Output is correct |
16 | Correct | 2 ms | 588 KB | Output is correct |
17 | Correct | 3 ms | 588 KB | Output is correct |
18 | Correct | 3 ms | 588 KB | Output is correct |
19 | Correct | 2 ms | 588 KB | Output is correct |
20 | Correct | 2 ms | 588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 588 KB | Output is correct |
2 | Correct | 3 ms | 588 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 3 ms | 588 KB | Output is correct |
5 | Correct | 3 ms | 588 KB | Output is correct |
6 | Correct | 2 ms | 588 KB | Output is correct |
7 | Correct | 3 ms | 588 KB | Output is correct |
8 | Correct | 3 ms | 588 KB | Output is correct |
9 | Correct | 2 ms | 588 KB | Output is correct |
10 | Correct | 2 ms | 588 KB | Output is correct |
11 | Correct | 3 ms | 588 KB | Output is correct |
12 | Correct | 3 ms | 588 KB | Output is correct |
13 | Correct | 2 ms | 588 KB | Output is correct |
14 | Correct | 3 ms | 588 KB | Output is correct |
15 | Correct | 3 ms | 588 KB | Output is correct |
16 | Correct | 2 ms | 588 KB | Output is correct |
17 | Correct | 3 ms | 588 KB | Output is correct |
18 | Correct | 3 ms | 588 KB | Output is correct |
19 | Correct | 2 ms | 588 KB | Output is correct |
20 | Correct | 2 ms | 588 KB | Output is correct |
21 | Correct | 627 ms | 28788 KB | Output is correct |
22 | Correct | 618 ms | 28740 KB | Output is correct |
23 | Correct | 618 ms | 28740 KB | Output is correct |
24 | Correct | 276 ms | 28612 KB | Output is correct |
25 | Correct | 268 ms | 28684 KB | Output is correct |
26 | Correct | 283 ms | 28612 KB | Output is correct |
27 | Correct | 286 ms | 28716 KB | Output is correct |
28 | Correct | 294 ms | 28916 KB | Output is correct |
29 | Correct | 292 ms | 28764 KB | Output is correct |
30 | Correct | 316 ms | 28900 KB | Output is correct |
31 | Correct | 308 ms | 28728 KB | Output is correct |
32 | Correct | 313 ms | 28904 KB | Output is correct |
33 | Correct | 423 ms | 28496 KB | Output is correct |
34 | Correct | 465 ms | 28576 KB | Output is correct |
35 | Correct | 413 ms | 28612 KB | Output is correct |
36 | Correct | 586 ms | 28740 KB | Output is correct |
37 | Correct | 596 ms | 28704 KB | Output is correct |
38 | Correct | 632 ms | 28768 KB | Output is correct |
39 | Correct | 264 ms | 28620 KB | Output is correct |
40 | Correct | 277 ms | 28612 KB | Output is correct |
41 | Correct | 266 ms | 28612 KB | Output is correct |
42 | Correct | 285 ms | 28740 KB | Output is correct |
43 | Correct | 282 ms | 28712 KB | Output is correct |
44 | Correct | 282 ms | 28740 KB | Output is correct |
45 | Correct | 309 ms | 28680 KB | Output is correct |
46 | Correct | 303 ms | 28732 KB | Output is correct |
47 | Correct | 306 ms | 28856 KB | Output is correct |
48 | Correct | 409 ms | 28612 KB | Output is correct |
49 | Correct | 423 ms | 28480 KB | Output is correct |
50 | Correct | 455 ms | 28740 KB | Output is correct |