# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
700977 |
2023-02-19T14:35:44 Z |
urosk |
Candies (JOI18_candies) |
C++14 |
|
540 ms |
28508 KB |
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define maxn 200005
ll n;
ll a[maxn];
bool cmp(pll x,pll y){
if(x.fi!=y.fi) return x.fi>y.fi;
return x.sc<y.sc;
}
multiset<pll> st;
multiset<pll,decltype(&cmp)> s(cmp);
void tc(){
cin >> n;
for(ll i = 1;i<=n;i++) cin >> a[i];
a[0] = a[n+1] = -llinf;
for(ll i = 0;i<=n+1;i++){
s.insert({a[i],i});
st.insert({i,a[i]});
}
ll cnt = 0,ans = 0;
while(cnt<(n+1)/2){
pll p = *s.begin();
ll i = p.sc,x = p.fi;
ans+=x;
cout<<ans<<endl;
auto it = st.lower_bound({i,x});
pll a,b,c,d;
b = *it;
st.erase(it);
s.erase(s.find({b.sc,b.fi}));
it = st.lower_bound({i,x});
c = *it;
st.erase(it);
s.erase(s.find({c.sc,c.fi}));
it = st.lower_bound({i,x});
it--;
a = *it;
st.erase(it);
s.erase(s.find({a.sc,a.fi}));
d.fi = a.sc+c.sc-b.sc;
d.sc = b.fi;
s.insert(d);
st.insert({d.sc,d.fi});
cnt++;
}
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
519 ms |
28300 KB |
Output is correct |
22 |
Correct |
517 ms |
28444 KB |
Output is correct |
23 |
Correct |
511 ms |
28408 KB |
Output is correct |
24 |
Correct |
230 ms |
28348 KB |
Output is correct |
25 |
Correct |
233 ms |
28296 KB |
Output is correct |
26 |
Correct |
250 ms |
28300 KB |
Output is correct |
27 |
Correct |
244 ms |
28296 KB |
Output is correct |
28 |
Correct |
257 ms |
28360 KB |
Output is correct |
29 |
Correct |
239 ms |
28364 KB |
Output is correct |
30 |
Correct |
288 ms |
28300 KB |
Output is correct |
31 |
Correct |
266 ms |
28492 KB |
Output is correct |
32 |
Correct |
250 ms |
28504 KB |
Output is correct |
33 |
Correct |
360 ms |
28384 KB |
Output is correct |
34 |
Correct |
351 ms |
28372 KB |
Output is correct |
35 |
Correct |
352 ms |
28392 KB |
Output is correct |
36 |
Correct |
540 ms |
28380 KB |
Output is correct |
37 |
Correct |
538 ms |
28384 KB |
Output is correct |
38 |
Correct |
534 ms |
28476 KB |
Output is correct |
39 |
Correct |
236 ms |
28444 KB |
Output is correct |
40 |
Correct |
259 ms |
28296 KB |
Output is correct |
41 |
Correct |
234 ms |
28364 KB |
Output is correct |
42 |
Correct |
251 ms |
28392 KB |
Output is correct |
43 |
Correct |
271 ms |
28304 KB |
Output is correct |
44 |
Correct |
247 ms |
28508 KB |
Output is correct |
45 |
Correct |
263 ms |
28296 KB |
Output is correct |
46 |
Correct |
259 ms |
28304 KB |
Output is correct |
47 |
Correct |
255 ms |
28444 KB |
Output is correct |
48 |
Correct |
339 ms |
28428 KB |
Output is correct |
49 |
Correct |
363 ms |
28328 KB |
Output is correct |
50 |
Correct |
350 ms |
28468 KB |
Output is correct |