답안 #890807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890807 2023-12-22T03:41:10 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    int n;
    cin>>n;
    set <int> st;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        st.insert(x);
    }
    int q;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        int ans=0;
        int next=x;
        while(!st.empty()){
            auto it=st.lower_bound(next);
            int mn=1e18;
            int cur=*it;
            if(it!=st.begin()){
                it--;
                mn=min(mn,abs(cur-*it));
                next=*it;
                it++;
            }
            it++;
            if(it!=st.end()){
                if(abs(cur-*it)<mn){
                    mn=abs(cur-*it);
                    next=*it;
                }
            }
            it--;
            if(mn!=1e18)ans+=mn;
            st.erase(it);
        }
        cout<<ans<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -