Submission #435920

# Submission time Handle Problem Language Result Execution time Memory
435920 2021-06-23T23:51:02 Z dariasc Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
277 ms 10800 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    pii a[n+1];
    for (int i = 0; i < n+1; i++) {
        int x; cin >> x;
        a[i] = {x, i};
    }
    sort(a, a + n+1);
    int mappin[n+1];
    for (int i = 0; i < n+1; i++) {
        pii x = a[i];
        mappin[x.second] = i;
    }
    cout << endl;

    int b[n];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(b, b + n);

    int direct[n];
    for (int i = 0; i < n; i++) {
        direct[i] = max(a[i].first - b[i], 0);
        if (i > 0) {
            direct[i] = max(direct[i], direct[i-1]);
        }
    }
    int offset[n];
    for (int i = 0; i < n; i++) {
        offset[i] = max(a[i+1].first - b[i], 0);
    }
    for (int i = n - 2; i >= 0; i--) {
        offset[i] = max(offset[i], offset[i+1]);
    }

    for (int i = 0; i < n+1; i++) {
        int j = mappin[i];
        if (j == 0) {
            cout << offset[0] << " ";
        } else if (j == n) {
            cout << direct[n-1] << " ";
        } else {
            cout << max(direct[j-1], offset[j]) << " ";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 328 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 4 ms 332 KB Output is correct
26 Correct 4 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 300 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 328 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 4 ms 332 KB Output is correct
26 Correct 4 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 300 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 248 ms 9892 KB Output is correct
34 Correct 231 ms 10248 KB Output is correct
35 Correct 277 ms 9928 KB Output is correct
36 Correct 229 ms 10460 KB Output is correct
37 Correct 245 ms 10800 KB Output is correct
38 Correct 232 ms 10620 KB Output is correct
39 Correct 232 ms 9632 KB Output is correct
40 Correct 264 ms 9668 KB Output is correct
41 Correct 235 ms 9720 KB Output is correct
42 Correct 276 ms 9720 KB Output is correct
43 Correct 244 ms 9604 KB Output is correct
44 Correct 238 ms 9288 KB Output is correct
45 Correct 232 ms 9380 KB Output is correct
46 Correct 255 ms 9280 KB Output is correct
47 Correct 256 ms 9400 KB Output is correct
48 Correct 222 ms 9364 KB Output is correct
49 Correct 265 ms 9920 KB Output is correct
50 Correct 264 ms 10004 KB Output is correct
51 Correct 271 ms 9912 KB Output is correct
52 Correct 248 ms 9996 KB Output is correct
53 Correct 235 ms 10004 KB Output is correct