답안 #389880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389880 2021-04-14T18:58:43 Z vishesh312 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
128 ms 10948 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

void solve(int tc) {
    int n;
    cin >> n;
    vector<int> b(n);
    vector<array<int, 2>> a(n+1);
    for (int i = 0; i < n+1; ++i) {
        cin >> a[i][0];
        a[i][1] = i;
    }
    for (auto &x : b) cin >> x;
    sort(all(a));
    sort(all(b));
    vector<int> p(n), s(n);
    p[0] = max(0, a[0][0] - b[0]);
    s[0] = max(0, a[n][0] - b[n-1]);
    for (int i = 1; i < n; ++i) {
        p[i] = max({0, p[i-1], a[i][0] - b[i]});
        s[i] = max({0, s[i-1], a[n-i][0] - b[n-1-i]});
    }
    vector<int> ans(n+1);
    ans[a[0][1]] = max(0, s.back());
    for (int i = 1; i < n; ++i) {
        ans[a[i][1]] = max(p[i-1], s[n-1-i]);
    }
    ans[a[n][1]] = max(0, p.back());
    for (int i = 0; i < n+1; ++i) cout << ans[i] << " ";
    cout << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# 결과 실행 시간 메모리 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 204 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 208 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
# 결과 실행 시간 메모리 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 204 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 208 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 368 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 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 204 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 208 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 368 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 101 ms 9940 KB Output is correct
34 Correct 109 ms 10368 KB Output is correct
35 Correct 128 ms 9988 KB Output is correct
36 Correct 119 ms 10500 KB Output is correct
37 Correct 110 ms 10948 KB Output is correct
38 Correct 106 ms 10648 KB Output is correct
39 Correct 119 ms 9684 KB Output is correct
40 Correct 105 ms 9752 KB Output is correct
41 Correct 104 ms 9796 KB Output is correct
42 Correct 105 ms 9832 KB Output is correct
43 Correct 110 ms 9672 KB Output is correct
44 Correct 102 ms 9284 KB Output is correct
45 Correct 103 ms 9340 KB Output is correct
46 Correct 124 ms 9340 KB Output is correct
47 Correct 100 ms 9504 KB Output is correct
48 Correct 100 ms 9444 KB Output is correct
49 Correct 122 ms 9956 KB Output is correct
50 Correct 113 ms 9956 KB Output is correct
51 Correct 107 ms 9944 KB Output is correct
52 Correct 127 ms 10052 KB Output is correct
53 Correct 109 ms 9948 KB Output is correct