Submission #898483

# Submission time Handle Problem Language Result Execution time Memory
898483 2024-01-04T18:09:00 Z Blagoj Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
83 ms 10952 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    pair<int, int> a[n + 1];
    for (int i = 0; i <= n; i++) cin >> a[i].first, a[i].second = i;
    sort(a, a + n + 1);
    int b[n];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(b, b + n);
    int leftAns[n + 1], rightAns[n + 1];
    leftAns[0] = max(a[0].first - b[0], 0);
    for (int i = 1; i < n; i++) leftAns[i] = max(leftAns[i - 1], max(a[i].first - b[i], 0));
    rightAns[n] = max(a[n].first - b[n - 1], 0);
    for (int i = n - 1; i > 0; i--) rightAns[i] = max(rightAns[i + 1], max(a[i].first - b[i - 1], 0));
    int ans[n + 1];
    for (int i = 0; i <= n; i++) {
        ans[a[i].second] = 0;
        if (i) ans[a[i].second]= max(ans[a[i].second], leftAns[i - 1]);
        if (i < n) ans[a[i].second]= max(ans[a[i].second], rightAns[i + 1]);
    }
    for (int i = 0; i <= n; i++) cout << ans[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 452 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 452 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 472 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 424 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 452 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 472 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 424 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 66 ms 10068 KB Output is correct
34 Correct 83 ms 10300 KB Output is correct
35 Correct 68 ms 10124 KB Output is correct
36 Correct 68 ms 10580 KB Output is correct
37 Correct 73 ms 10936 KB Output is correct
38 Correct 73 ms 10952 KB Output is correct
39 Correct 71 ms 9868 KB Output is correct
40 Correct 69 ms 9752 KB Output is correct
41 Correct 69 ms 9812 KB Output is correct
42 Correct 79 ms 9876 KB Output is correct
43 Correct 68 ms 9876 KB Output is correct
44 Correct 79 ms 9444 KB Output is correct
45 Correct 68 ms 9552 KB Output is correct
46 Correct 68 ms 9412 KB Output is correct
47 Correct 64 ms 9508 KB Output is correct
48 Correct 64 ms 9332 KB Output is correct
49 Correct 70 ms 10068 KB Output is correct
50 Correct 73 ms 10324 KB Output is correct
51 Correct 71 ms 10068 KB Output is correct
52 Correct 70 ms 10064 KB Output is correct
53 Correct 70 ms 10068 KB Output is correct