제출 #891211

#제출 시각아이디문제언어결과실행 시간메모리
891211vjudge1Bitaro's travel (JOI23_travel)C++17
15 / 100
3072 ms2356 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 120000; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for(int i = 0;i < n; i++){ cin >> a[i]; } int q; cin >> q; while(q--){ int x; cin >> x; int it = upper_bound(all(a), x) - a.begin(); int it1 = it - 1; int sum = 0; while(true){ if(it >= n && it1 < 0) break; if(it1 < 0){ sum+= abs(a.back() - x); break; }else if(it >= n){ sum+= abs(a[0] - x); break; }else if(abs(a[it1] - x) > abs(a[it] - x)){ sum+= abs(a[it] - x); x = a[it]; it++; }else{ sum+= abs(a[it1] - x); x = a[it1]; it1--; } } cout << sum << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...