답안 #807577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
807577 2023-08-04T19:42:14 Z annabeth9680 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
83 ms 10844 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N; cin >> N;
    vector<pair<int,int>> arr(N+1);
    for(int i = 0;i<=N;++i){
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr.begin(),arr.end());
    vector<int> brr(N);
    for(int i = 0;i<N;++i) cin >> brr[i];
    sort(brr.begin(),brr.end());
    vector<int> pref(N),suf(N);
    for(int i = 0;i<N;++i){
        if(i == 0){
            pref[i] = max(arr[i].first-brr[i],0);
        }
        else{
            pref[i] = max(max(arr[i].first-brr[i],0),pref[i-1]);
        }
    }
    for(int i = N-1;i>=0;--i){
        if(i == N-1){
            suf[i] = max(arr[i+1].first-brr[i],0);
        }
        else{
            suf[i] = max(max(arr[i+1].first-brr[i],0),suf[i+1]);
        }
    }
    vector<int> ans(N+1);
    for(int i = 0;i<=N;++i){
        if(i == 0) ans[arr[i].second] = suf[i];
        else if(i == N) ans[arr[i].second] = pref[N-1];
        else{
            ans[arr[i].second] = max(suf[i],pref[i-1]);
        }
    }
    for(int i = 0;i<=N;++i) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 312 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 312 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 376 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 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 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 328 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 312 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 376 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 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 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 328 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 69 ms 9996 KB Output is correct
34 Correct 73 ms 10312 KB Output is correct
35 Correct 70 ms 10060 KB Output is correct
36 Correct 73 ms 10516 KB Output is correct
37 Correct 76 ms 10844 KB Output is correct
38 Correct 72 ms 10664 KB Output is correct
39 Correct 71 ms 9760 KB Output is correct
40 Correct 71 ms 9740 KB Output is correct
41 Correct 71 ms 9900 KB Output is correct
42 Correct 70 ms 9764 KB Output is correct
43 Correct 83 ms 9768 KB Output is correct
44 Correct 68 ms 9352 KB Output is correct
45 Correct 69 ms 9360 KB Output is correct
46 Correct 72 ms 9360 KB Output is correct
47 Correct 65 ms 9440 KB Output is correct
48 Correct 66 ms 9492 KB Output is correct
49 Correct 71 ms 9996 KB Output is correct
50 Correct 72 ms 10080 KB Output is correct
51 Correct 73 ms 10072 KB Output is correct
52 Correct 72 ms 10068 KB Output is correct
53 Correct 72 ms 9996 KB Output is correct