Submission #639826

# Submission time Handle Problem Language Result Execution time Memory
639826 2022-09-12T06:38:14 Z danikoynov Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
397 ms 19360 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 10;

struct element
{
    int x, idx;

    element(int _x = 0, int _idx = 0)
    {
        x = _x;
        idx = _idx;
    }

    bool operator < (const element &e) const
    {
        return x < e.x;
    }
} e[maxn];

int n, a[maxn], b[maxn], ans[maxn];

void solve()
{
    cin >> n;
    n ++;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        e[i] = element(a[i], i);
    }

    sort(e + 1, e + n + 1);

    for (int i = 1; i < n; i ++)
        cin >> b[i];

    sort(b + 1, b + n);

    multiset < int > st;
    for (int i = 1; i < n; i ++)
        st.insert(max(0, e[i + 1].x - b[i]));

    for (int i = 1; i <= n; i ++)
    {
        ans[e[i].idx] = *st.rbegin();
        ///cout << "fine " << e[i].idx << endl;
        if (i != n)
        {
            st.erase(st.find(max(0, e[i + 1].x - b[i])));
            ///cout << e[i + 1].x - b[i] << " " << e[i].x - b[i] << endl;
            st.insert(max(0, e[i].x - b[i]));

        }
    }

    for (int i = 1; i <= n; i ++)
        cout << ans[i] << " ";

    cout << endl;

}
int main()
{
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 1 ms 1872 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1872 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 1 ms 1872 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1872 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 3 ms 2004 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 3 ms 2008 KB Output is correct
18 Correct 3 ms 2004 KB Output is correct
19 Correct 3 ms 2012 KB Output is correct
20 Correct 3 ms 2004 KB Output is correct
21 Correct 3 ms 2004 KB Output is correct
22 Correct 3 ms 2004 KB Output is correct
23 Correct 3 ms 2004 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 4 ms 2004 KB Output is correct
26 Correct 3 ms 2004 KB Output is correct
27 Correct 3 ms 2004 KB Output is correct
28 Correct 4 ms 2132 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 4 ms 2004 KB Output is correct
31 Correct 3 ms 2004 KB Output is correct
32 Correct 3 ms 2012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 1 ms 1872 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1872 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 3 ms 2004 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 3 ms 2008 KB Output is correct
18 Correct 3 ms 2004 KB Output is correct
19 Correct 3 ms 2012 KB Output is correct
20 Correct 3 ms 2004 KB Output is correct
21 Correct 3 ms 2004 KB Output is correct
22 Correct 3 ms 2004 KB Output is correct
23 Correct 3 ms 2004 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 4 ms 2004 KB Output is correct
26 Correct 3 ms 2004 KB Output is correct
27 Correct 3 ms 2004 KB Output is correct
28 Correct 4 ms 2132 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 4 ms 2004 KB Output is correct
31 Correct 3 ms 2004 KB Output is correct
32 Correct 3 ms 2012 KB Output is correct
33 Correct 275 ms 18156 KB Output is correct
34 Correct 303 ms 18968 KB Output is correct
35 Correct 301 ms 18340 KB Output is correct
36 Correct 285 ms 19004 KB Output is correct
37 Correct 303 ms 19360 KB Output is correct
38 Correct 295 ms 19280 KB Output is correct
39 Correct 354 ms 18124 KB Output is correct
40 Correct 362 ms 18032 KB Output is correct
41 Correct 355 ms 18252 KB Output is correct
42 Correct 397 ms 18304 KB Output is correct
43 Correct 336 ms 18132 KB Output is correct
44 Correct 262 ms 17688 KB Output is correct
45 Correct 272 ms 17748 KB Output is correct
46 Correct 265 ms 17612 KB Output is correct
47 Correct 262 ms 17940 KB Output is correct
48 Correct 264 ms 17996 KB Output is correct
49 Correct 366 ms 18716 KB Output is correct
50 Correct 333 ms 18640 KB Output is correct
51 Correct 372 ms 18700 KB Output is correct
52 Correct 375 ms 18636 KB Output is correct
53 Correct 356 ms 18632 KB Output is correct