답안 #826314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826314 2023-08-15T12:44:05 Z xink Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
156 ms 7016 KB
#include <iostream>
#include <vector>
#include <utility>
#include <sstream>
#include <climits>
#include <cstring>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
const ll mod = 1e9 + 7;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int maxn = 2e5 + 5;
ii a[maxn];
int b[maxn], pref[maxn], suff[maxn], ans[maxn];

void solve()
{
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(a, a + n + 1);
    sort(b, b + n);
    pref[0] = max(a[0].first - b[0], 0);
    for (int i = 1; i < n; i++)
    {
        pref[i] = max(pref[i - 1], max(a[i].first - b[i], 0));
    }
    suff[n] = max(a[n].first - b[n - 1], 0);
    for (int i = n - 1; i > 0; i--)
    {
        suff[i] = max(suff[i + 1], max(a[i].first - b[i - 1], 0));
    }
    for (int i = 0; i <= n; i++)
    {
        int oddity = 0;
        if (i != 0)
        {
            oddity = max(oddity, pref[i - 1]);
        }
        if (i != n)
        {
            oddity = max(oddity, suff[i + 1]);
        }
        ans[a[i].second] = oddity;
    }
    for (int i = 0; i <= n; i++) {
        cout << ans[i] << " ";
    }
}

int main()
{
    // freopen("input_text", "r", stdin);
    // freopen("output_text", "w", stdout);
    // ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t-- > 0)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 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 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 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 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 143 ms 6240 KB Output is correct
34 Correct 156 ms 6588 KB Output is correct
35 Correct 148 ms 6240 KB Output is correct
36 Correct 151 ms 6660 KB Output is correct
37 Correct 156 ms 7016 KB Output is correct
38 Correct 149 ms 6796 KB Output is correct
39 Correct 147 ms 5964 KB Output is correct
40 Correct 145 ms 5980 KB Output is correct
41 Correct 147 ms 5964 KB Output is correct
42 Correct 148 ms 5992 KB Output is correct
43 Correct 155 ms 5896 KB Output is correct
44 Correct 145 ms 5708 KB Output is correct
45 Correct 144 ms 5624 KB Output is correct
46 Correct 143 ms 5596 KB Output is correct
47 Correct 144 ms 5464 KB Output is correct
48 Correct 145 ms 5460 KB Output is correct
49 Correct 150 ms 6092 KB Output is correct
50 Correct 150 ms 6152 KB Output is correct
51 Correct 155 ms 6200 KB Output is correct
52 Correct 149 ms 6152 KB Output is correct
53 Correct 150 ms 6092 KB Output is correct