forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathacpc11b.cpp
More file actions
30 lines (30 loc) · 694 Bytes
/
Copy pathacpc11b.cpp
File metadata and controls
30 lines (30 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 2014-04-25
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int a[1000], b[1000];
int main() {
int T; cin >> T;
while (T--) {
int M, N; cin >> M;
for (int i = 0; i < M; i++) {
cin >> a[i];
}
cin >> N;
for (int i = 0; i < N; i++) {
cin >> b[i];
}
sort(a, a+M); sort(b, b+N);
int i = 0, j = 0; int best = 1e9;
while (i < M && j < N) {
best = min(best, abs(a[i] - b[j]));
if (a[i] <= b[j]) {
i++;
} else if (a[i] > b[j]) {
j++;
}
}
cout << best << endl;
}
}