Submission #979845

# Submission time Handle Problem Language Result Execution time Memory
979845 2024-05-11T13:36:06 Z IUA_Hasin Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
175 ms 25500 KB
#include <bits/stdc++.h>

#define ll                                  long long
#define ld                                  long double
#define endl                                "\n"

using namespace std;


int main(){
    #if __has_include("LOCAL.hh")
        #include "LOCAL.hh"
    #endif

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        using namespace std::chrono;
        cout << fixed << setprecision(9);
        auto begin = steady_clock::now();
    #else
        std::ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    #endif



    ll n;
    cin>>n;
    vector<pair<ll, ll>> v;
    ll brr[n];

    for(int i=0; i<n+1; i++){
        ll x;
        cin>>x;
        v.push_back({x, i});
    }

    for(int i=0; i<n; i++){
        cin>>brr[i];
    }
    sort(v.begin(), v.end());
    sort(brr, brr+n);

    ll diff1[n];
    ll diff2[n];
    for(int i=0; i<n; i++){
        ll b = brr[i];
        ll a1 = v[i].first;
        ll a2 = v[i+1].first;
        ll temp1 = max((ll)0, a1-b);
        ll temp2 = max((ll)0, a2-b);
        diff1[i] = temp1;
        diff2[i] = temp2;
    }

    multiset<ll> s;
    for(int i=0; i<n; i++){
        s.insert(diff1[i]);
    }

    ll ans[n+1];
    ll r = n;
    while(r>=0){
        // for(auto u : s){
        //     cout << u << " ";
        // }
        // cout<<endl;
        //cout<<endl;
        ll tempind = v[r].second;
        auto it = s.end();
        it--;
        ll temp = *it;
        ans[tempind] = temp;
        //cout << temp << " " << tempind << endl;
        //cout<<endl;
        //s.erase(it);
        ll next = diff2[r-1];
        ll now = diff1[r-1];
        auto dlt = s.find(now);
        if(dlt==s.end()){
            dlt--;
        }
        s.erase(dlt);
        s.insert(next);

        r--;
    }

    for(int i=0; i<n+1; i++){
        cout << ans[i] << " ";
    }
    cout<<endl;
    






    #ifdef LOCAL
        auto end = steady_clock::now();
        cout << "\nTime : " 
             << (ld)duration_cast<nanoseconds>
                (end - begin).count()/1000000000 
             << "s" << endl;
    #endif


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 144 ms 23680 KB Output is correct
34 Correct 163 ms 24436 KB Output is correct
35 Correct 143 ms 24776 KB Output is correct
36 Correct 155 ms 24252 KB Output is correct
37 Correct 154 ms 25500 KB Output is correct
38 Correct 147 ms 24620 KB Output is correct
39 Correct 169 ms 24152 KB Output is correct
40 Correct 164 ms 23996 KB Output is correct
41 Correct 161 ms 23980 KB Output is correct
42 Correct 175 ms 24052 KB Output is correct
43 Correct 164 ms 23488 KB Output is correct
44 Correct 136 ms 23232 KB Output is correct
45 Correct 136 ms 23228 KB Output is correct
46 Correct 136 ms 23080 KB Output is correct
47 Correct 129 ms 24268 KB Output is correct
48 Correct 137 ms 23696 KB Output is correct
49 Correct 166 ms 25024 KB Output is correct
50 Correct 170 ms 24256 KB Output is correct
51 Correct 166 ms 24388 KB Output is correct
52 Correct 169 ms 24132 KB Output is correct
53 Correct 171 ms 24216 KB Output is correct