답안 #974899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974899 2024-05-04T06:32:31 Z berr Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
0 ms 348 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)abs(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)abs(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 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -