Submission #556089

# Submission time Handle Problem Language Result Execution time Memory
556089 2022-05-02T10:48:13 Z alextodoran Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
261 ms 19404 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200000;

int N;
int A[N_MAX + 2];
int B[N_MAX + 2];

int p[N_MAX + 2];
int id[N_MAX + 2];

int answer[N_MAX + 2];

multiset <int> s;

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

    cin >> N;
    for (int i = 1; i <= N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
    }

    iota(p + 1, p + (N + 1) + 1, 1);
    sort(p + 1, p + (N + 1) + 1, [&] (const int &i, const int &j) {
        return A[i] < A[j];
    });
    sort(B + 1, B + N + 1);

    for (int i = 1; i <= (N + 1); i++) {
        id[p[i]] = i;
    }
    sort(A + 1, A + (N + 1) + 1);

    for (int i = 1; i <= N; i++) {
        s.insert(max(0, A[i + 1] - B[i]));
    }
    for (int i = 1; i <= N + 1; i++) {
        answer[i] = *s.rbegin();
        if (i <= N) {
            s.erase(s.find(max(0, A[i + 1] - B[i])));
            s.insert(max(0, A[i] - B[i]));
        }
    }
    for (int i = 1; i <= N + 1; i++) {
        cout << answer[id[i]] << " ";
    }
    cout << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 500 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 500 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 188 ms 18172 KB Output is correct
34 Correct 209 ms 18912 KB Output is correct
35 Correct 196 ms 18332 KB Output is correct
36 Correct 204 ms 18836 KB Output is correct
37 Correct 199 ms 19404 KB Output is correct
38 Correct 204 ms 19112 KB Output is correct
39 Correct 246 ms 18128 KB Output is correct
40 Correct 259 ms 17976 KB Output is correct
41 Correct 250 ms 18252 KB Output is correct
42 Correct 254 ms 18304 KB Output is correct
43 Correct 254 ms 18088 KB Output is correct
44 Correct 170 ms 17448 KB Output is correct
45 Correct 186 ms 17640 KB Output is correct
46 Correct 172 ms 17484 KB Output is correct
47 Correct 153 ms 17992 KB Output is correct
48 Correct 170 ms 18008 KB Output is correct
49 Correct 252 ms 18656 KB Output is correct
50 Correct 258 ms 18684 KB Output is correct
51 Correct 261 ms 18640 KB Output is correct
52 Correct 259 ms 18636 KB Output is correct
53 Correct 260 ms 18668 KB Output is correct