#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e9 + 10;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
int x[n + 2] = {};
for(int i = 1; i <= n; i++)
cin >> x[i];
int q;
cin >> q;
while(q--) {
ll ans = 0;
ll cur;
cin >> cur;
int cnt = 0;
int l = 0, r = 0;
while(l < n && x[l + 1] <= cur) l++;
while(r <= n && x[r] <= cur) r++;
while(cnt <= n) {
int w1 = (l > 0 ? cur - x[l] : INF);
int w2 = (r < n + 1 ? x[r] - cur : INF);
ans += min(w1, w2);
if(w1 <= w2) cur = x[l--];
else cur = x[r++];
cnt++;
}
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |