Submission #625257

# Submission time Handle Problem Language Result Execution time Memory
625257 2022-08-09T17:34:39 Z boris_mihov Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
119 ms 10836 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const llong INF = 1e18;

int n;
int a[MAXN];
int b[MAXN];
int idx[MAXN];
int output[MAXN];
int prefix[MAXN];
int suffix[MAXN];

void solve()
{
    std::iota(idx + 1, idx + 2 + n, 1);
    std::sort(idx + 1, idx + 2 + n, [&](int x, int y)
    {
        return a[x] < a[y];
    });

    std::sort(a + 1, a + 2 + n);
    std::sort(b + 1, b + 1 + n);
    
    for (int i = 1 ; i <= n ; ++i)
    {
        prefix[i] = std::max(prefix[i - 1], a[i] - b[i]);
    }

    for (int i = n ; i >= 1 ; --i)
    {
        suffix[i] = std::max(suffix[i + 1], a[i+1] - b[i]);
    }

    for (int i = 1 ; i <= n + 1 ; ++i)
    {
        output[idx[i]] = std::max(prefix[i - 1], suffix[i]);
    }

    for (int i = 1 ; i <= n + 1 ; ++i)
    {
        std::cout << output[i] << ' ';
    }

    std::cout << '\n';
}

void read()
{
    std::cin >> n;
    for (int i = 1 ; i <= n + 1 ; ++i) std::cin >> a[i];
    for (int i = 1 ; i <= n ; ++i) std::cin >> b[i];
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 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 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 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 0 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 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 0 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 98 ms 9928 KB Output is correct
34 Correct 119 ms 10316 KB Output is correct
35 Correct 97 ms 10036 KB Output is correct
36 Correct 97 ms 10532 KB Output is correct
37 Correct 107 ms 10836 KB Output is correct
38 Correct 102 ms 10684 KB Output is correct
39 Correct 98 ms 9704 KB Output is correct
40 Correct 106 ms 9756 KB Output is correct
41 Correct 105 ms 9788 KB Output is correct
42 Correct 98 ms 9880 KB Output is correct
43 Correct 103 ms 9676 KB Output is correct
44 Correct 101 ms 9292 KB Output is correct
45 Correct 95 ms 9396 KB Output is correct
46 Correct 95 ms 9456 KB Output is correct
47 Correct 78 ms 9424 KB Output is correct
48 Correct 74 ms 9460 KB Output is correct
49 Correct 100 ms 9932 KB Output is correct
50 Correct 105 ms 9944 KB Output is correct
51 Correct 106 ms 9988 KB Output is correct
52 Correct 99 ms 10048 KB Output is correct
53 Correct 105 ms 9988 KB Output is correct