Submission #573116

# Submission time Handle Problem Language Result Execution time Memory
573116 2022-06-05T23:37:23 Z teki Just Long Neckties (JOI20_ho_t1) C++11
100 / 100
215 ms 31088 KB
#include <bits/stdc++.h>

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000007

using namespace std;

vector<pair<bool,int>> pref[200005];
multiset<int> pos;

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;

    pair<int,int> niza[n+1];
    for (int i = 0; i<n+1; i++) cin>>niza[i].first;
    for (int i = 0; i<n+1; i++) niza[i].second = i;

    int init[n];
    for (int i = 0; i<n; i++) cin>>init[i];

    sort(niza,niza+(n+1));
    sort(init,init+n);

    for (int i = 0; i<n; i++) {
        int br = init[i];
        int prv = niza[i].first;
        int vtor = niza[i+1].first;

        if (vtor-br > 0) {
            pref[0].pb({1,vtor-br});
            pref[i+1].pb({0,vtor-br});
        }

        if (prv-br > 0) {
            pref[i+1].pb({1,prv-br});
        }
    }

    int res[n+1];
    MS(res,0);

    for (int i = 0; i<n+1; i++) {
        sort(pref[i].rbegin(),pref[i].rend());

        for (auto it:pref[i]) {
            if (it.first == 0) pos.erase(pos.find(it.second));
            else pos.insert(it.second);
        }

        if (pos.size() == 0) continue;

        auto orel = pos.end();
        orel--;

        res[niza[i].second] = *orel;
    }

    for (int i = 0; i<n+1; i++) cout<<res[i]<<" ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 4 ms 5096 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5204 KB Output is correct
26 Correct 4 ms 5204 KB Output is correct
27 Correct 4 ms 5100 KB Output is correct
28 Correct 3 ms 5204 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5204 KB Output is correct
32 Correct 4 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 4 ms 5096 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5204 KB Output is correct
26 Correct 4 ms 5204 KB Output is correct
27 Correct 4 ms 5100 KB Output is correct
28 Correct 3 ms 5204 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5204 KB Output is correct
32 Correct 4 ms 5204 KB Output is correct
33 Correct 158 ms 23708 KB Output is correct
34 Correct 199 ms 29176 KB Output is correct
35 Correct 140 ms 22076 KB Output is correct
36 Correct 191 ms 30288 KB Output is correct
37 Correct 200 ms 31088 KB Output is correct
38 Correct 190 ms 30776 KB Output is correct
39 Correct 209 ms 29788 KB Output is correct
40 Correct 194 ms 29524 KB Output is correct
41 Correct 204 ms 29880 KB Output is correct
42 Correct 194 ms 29752 KB Output is correct
43 Correct 189 ms 29576 KB Output is correct
44 Correct 131 ms 28952 KB Output is correct
45 Correct 135 ms 29132 KB Output is correct
46 Correct 132 ms 28936 KB Output is correct
47 Correct 90 ms 16068 KB Output is correct
48 Correct 89 ms 16000 KB Output is correct
49 Correct 205 ms 30344 KB Output is correct
50 Correct 197 ms 30328 KB Output is correct
51 Correct 215 ms 30520 KB Output is correct
52 Correct 200 ms 30348 KB Output is correct
53 Correct 202 ms 30340 KB Output is correct