Submission #203459

# Submission time Handle Problem Language Result Execution time Memory
203459 2020-02-20T19:04:25 Z tri Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
320 ms 8588 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

const int MAXN = 2e5 + 10;

pi fr[MAXN];
int orig[MAXN];

int st[MAXN][2];
int odd[MAXN][2];

int ans[MAXN];

int main() {
    int N;
    cin >> N;

    for (int i = 1; i <= N + 1; i++) {
        int x;
        cin >> x;
        fr[i] = {x, i};
    }
    sort(fr + 1, fr + N + 2);

    for (int i = 1; i <= N; i++) {
        cin >> orig[i];
    }
    sort(&orig[1], &orig[N + 1]);

    st[0][0] = st[0][1] = 0;
    st[N + 1][0] = st[N + 1][1] = 0;

    for (int i = 1; i <= N; i++) {
        st[i][0] = max(fr[i].f - orig[i], 0);
        st[i][1] = max(fr[i + 1].f - orig[i], 0);
    }

    for (int i = 1; i <= N; i++) {
        odd[i][0] = max(st[i][0], odd[i - 1][0]);
    }

    for (int i = N; i >= 1; i--) {
        odd[i][1] = max(st[i][1], odd[i + 1][1]);
    }

    for (int i = 1; i <= N + 1; i++) {
        int k = fr[i].s;
        ans[k] = max(odd[i - 1][0], odd[i][1]);
    }

    cout << ans[1];
    for (int i = 2; i <= N + 1; i++) {
        cout << " " << ans[i];
    }
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 280 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 280 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 8 ms 376 KB Output is correct
18 Correct 7 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 7 ms 376 KB Output is correct
23 Correct 7 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 7 ms 376 KB Output is correct
29 Correct 7 ms 448 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 9 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 280 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 8 ms 376 KB Output is correct
18 Correct 7 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 7 ms 376 KB Output is correct
23 Correct 7 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 7 ms 376 KB Output is correct
29 Correct 7 ms 448 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 9 ms 376 KB Output is correct
33 Correct 292 ms 7928 KB Output is correct
34 Correct 302 ms 8184 KB Output is correct
35 Correct 298 ms 7928 KB Output is correct
36 Correct 296 ms 8428 KB Output is correct
37 Correct 306 ms 8588 KB Output is correct
38 Correct 310 ms 8440 KB Output is correct
39 Correct 297 ms 7544 KB Output is correct
40 Correct 298 ms 7544 KB Output is correct
41 Correct 302 ms 7672 KB Output is correct
42 Correct 294 ms 7544 KB Output is correct
43 Correct 300 ms 7544 KB Output is correct
44 Correct 284 ms 7288 KB Output is correct
45 Correct 291 ms 7288 KB Output is correct
46 Correct 291 ms 7160 KB Output is correct
47 Correct 298 ms 7204 KB Output is correct
48 Correct 296 ms 7160 KB Output is correct
49 Correct 310 ms 7928 KB Output is correct
50 Correct 310 ms 7932 KB Output is correct
51 Correct 320 ms 7928 KB Output is correct
52 Correct 307 ms 7800 KB Output is correct
53 Correct 310 ms 7928 KB Output is correct