Submission #1088101

# Submission time Handle Problem Language Result Execution time Memory
1088101 2024-09-13T21:42:12 Z DobromirAngelov Candies (JOI18_candies) C++14
100 / 100
354 ms 30464 KB
#include<bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second

using namespace std;

const int MAXN=2e5+5;
const long long INF=1e18+5;

int n;
long long a[MAXN];
multiset<pair<long long,int> > vals;
set<pair<int,long long> > inds;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];

    for(int i=1;i<=n;i++)
    {
        vals.insert({-a[i],i});
        inds.insert({i,-a[i]});
    }
    vals.insert({INF,0});
    vals.insert({INF,n+1});
    inds.insert({0,INF});
    inds.insert({n+1,INF});

    long long ans=0;
    for(int i=1;i<=(n+1)/2;i++)
    {
        auto cur=(*vals.begin());
        ans-=cur.fi;
        cout<<ans<<endl;

        auto it=inds.lower_bound({cur.se,-INF});
        it--;
        auto l=(*it);
        inds.erase(it++);
        auto m=(*it);
        inds.erase(it++);
        auto r=(*it);
        inds.erase(it);

        vals.erase({l.se, l.fi});
        vals.erase({m.se, m.fi});
        vals.erase({r.se, r.fi});

        vals.insert({l.se+r.se-m.se, m.fi});
        inds.insert({m.fi, l.se+r.se-m.se});
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 1 ms 752 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 1 ms 752 KB Output is correct
18 Correct 2 ms 732 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 1 ms 752 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 1 ms 752 KB Output is correct
18 Correct 2 ms 732 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 332 ms 30292 KB Output is correct
22 Correct 312 ms 30292 KB Output is correct
23 Correct 354 ms 30288 KB Output is correct
24 Correct 155 ms 30128 KB Output is correct
25 Correct 162 ms 30292 KB Output is correct
26 Correct 160 ms 30288 KB Output is correct
27 Correct 171 ms 30320 KB Output is correct
28 Correct 189 ms 30288 KB Output is correct
29 Correct 174 ms 30348 KB Output is correct
30 Correct 182 ms 30364 KB Output is correct
31 Correct 192 ms 30412 KB Output is correct
32 Correct 190 ms 30272 KB Output is correct
33 Correct 239 ms 30128 KB Output is correct
34 Correct 238 ms 30208 KB Output is correct
35 Correct 238 ms 30088 KB Output is correct
36 Correct 333 ms 30284 KB Output is correct
37 Correct 304 ms 30292 KB Output is correct
38 Correct 346 ms 30464 KB Output is correct
39 Correct 155 ms 30288 KB Output is correct
40 Correct 153 ms 30288 KB Output is correct
41 Correct 162 ms 30292 KB Output is correct
42 Correct 171 ms 30292 KB Output is correct
43 Correct 172 ms 30288 KB Output is correct
44 Correct 180 ms 30308 KB Output is correct
45 Correct 179 ms 30268 KB Output is correct
46 Correct 187 ms 30356 KB Output is correct
47 Correct 188 ms 30288 KB Output is correct
48 Correct 253 ms 30136 KB Output is correct
49 Correct 238 ms 30288 KB Output is correct
50 Correct 238 ms 30276 KB Output is correct