Submission #503534

# Submission time Handle Problem Language Result Execution time Memory
503534 2022-01-08T10:22:08 Z FronPaw Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
93 ms 14712 KB
#include <bits/stdc++.h>
#define mod 1000000007
#define int long long
// https://www.youtube.com/watch?v=t5GDacP_2pQ
using namespace std;
int pow (int a, int b)
{
    int rez = 1;
    while (b)
    {
        if (b&1)
            rez = (rez * a) % mod;
        a = (a * a) % mod;
        b>>=1;
    }
    return rez;
}
pair <int, int> a[200010];
int b[200010], n;
int ans[200010];
int st[200010];
int dr[200010];
void solve ()
{
    cin >> n;
    for (int i = 1;i<=n+1;++i)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i = 1;i<=n;++i)
        cin >> b[i];
    sort(a + 1, a + n + 2);
    sort(b + 1, b + n + 1);
    for (int i = 1;i<=n;++i)
        st[i] = max(st[i-1], max(0LL, a[i].first - b[i]));
    for (int i = n;i>=1;--i)
        dr[i] = max(dr[i+1], max(0LL, a[i+1].first - b[i]));
    for (int i = n + 1;i>=1;--i)
        ans[a[i].second] = max(dr[i], st[i-1]);
    for (int i = 1;i<=n+1;++i)
        cout << ans[i] << ' ';
    cout << '\n';
}
main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
}

Compilation message

ho_t1.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main ()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 332 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 332 KB Output is correct
17 Correct 1 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 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 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 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 332 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 332 KB Output is correct
17 Correct 1 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 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 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 1 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 85 ms 10728 KB Output is correct
34 Correct 81 ms 11108 KB Output is correct
35 Correct 81 ms 10764 KB Output is correct
36 Correct 82 ms 11244 KB Output is correct
37 Correct 86 ms 11588 KB Output is correct
38 Correct 87 ms 11656 KB Output is correct
39 Correct 88 ms 10520 KB Output is correct
40 Correct 83 ms 10492 KB Output is correct
41 Correct 80 ms 10664 KB Output is correct
42 Correct 81 ms 10512 KB Output is correct
43 Correct 81 ms 10496 KB Output is correct
44 Correct 80 ms 10156 KB Output is correct
45 Correct 76 ms 10180 KB Output is correct
46 Correct 80 ms 10052 KB Output is correct
47 Correct 86 ms 10272 KB Output is correct
48 Correct 79 ms 14024 KB Output is correct
49 Correct 87 ms 14708 KB Output is correct
50 Correct 93 ms 14644 KB Output is correct
51 Correct 87 ms 14644 KB Output is correct
52 Correct 84 ms 14712 KB Output is correct
53 Correct 88 ms 14660 KB Output is correct