답안 #974904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974904 2024-05-04T06:38:53 Z berr Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
154 ms 26276 KB
#include <bits/stdc++.h>
using namespace std; 
#define int long long
const int N=5005, INF=1e18;
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   
    int n; cin >> n;

    vector<int> a(n+1), b(n);

    for(auto &i: a) cin >> i;
    for(auto &i: b) cin >> i;

    vector<int> id(n+1);
    
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int x, int y){
        return a[x] < a[y];
    });

    sort(b.begin(), b.end());

    priority_queue<array<int, 3>> pq;
    vector<int> p(n), ans(n+1);

    for(int i=0; i<n; i++){
       // cout<<id[i+1]<<" ";
        pq.push({(int)max(0LL, a[id[i+1]]-b[i]), i, id[i+1]});
        p[i]=id[i+1];
    }
    ans[id[0]]=pq.top()[0];

    for(int i=1; i<=n; i++){
        pq.push({(int)max(0LL, a[id[i-1]]-b[i-1]), i-1, id[i-1]});
        p[i-1]=id[i-1];
        while(pq.size() && p[pq.top()[1]]!=pq.top()[2]) pq.pop();
        
        ans[id[i]]=pq.top()[0];
    }
    
    for(auto &i: ans) cout<<i<<" ";

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 728 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 728 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 87 ms 25788 KB Output is correct
34 Correct 90 ms 25020 KB Output is correct
35 Correct 95 ms 24836 KB Output is correct
36 Correct 89 ms 26120 KB Output is correct
37 Correct 92 ms 25748 KB Output is correct
38 Correct 90 ms 24512 KB Output is correct
39 Correct 126 ms 24708 KB Output is correct
40 Correct 137 ms 24204 KB Output is correct
41 Correct 127 ms 24512 KB Output is correct
42 Correct 137 ms 24868 KB Output is correct
43 Correct 123 ms 24220 KB Output is correct
44 Correct 100 ms 18888 KB Output is correct
45 Correct 116 ms 18516 KB Output is correct
46 Correct 103 ms 18904 KB Output is correct
47 Correct 80 ms 26276 KB Output is correct
48 Correct 78 ms 26044 KB Output is correct
49 Correct 148 ms 26020 KB Output is correct
50 Correct 134 ms 25532 KB Output is correct
51 Correct 154 ms 24740 KB Output is correct
52 Correct 134 ms 24764 KB Output is correct
53 Correct 132 ms 25024 KB Output is correct