Problem 我代码会WA 8/15:
// G.cpp 3s 1G
// 007 - CP Classes
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
using ll = long long;
const int N = 3e6 + 5;
ll n, Q;
ll a[N], b[N];
inline ll read() {
ll x = 0;
int f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
// freopen("../in_out/.out", "w", stdout);
n = read();
for (int i = 0; i < n; ++i) {
a[i] = read();
}
cin >> Q;
for (int i = 0; i < Q; ++i) {
b[i] = read();
}
sort(a, a + n);
// for (int i = 0; i < n; ++i) cout << a[i] << ' ';
// cout <<
// "\n------------------\n--------------------------\n---------------------------------------------\n----------------------------\n-------------------\n";
for (int i = 0; i < Q; ++i) {
int idx = upper_bound(a, a + n, b[i]) - a;
cout << min(abs(b[i] - a[idx]), abs(b[i] - a[idx - 1])) << '\n';
}
return 0;
}