-
Notifications
You must be signed in to change notification settings - Fork 0
/
DressEmInVests.java
57 lines (50 loc) · 1.26 KB
/
DressEmInVests.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* https://codeforces.com/contest/161/problem/A
#binary-search #greedy #two-pointer
compare min value of array a and array b.
max value of array a and array b.
note: when it's satisfying the condition
*/
import java.util.ArrayList;
import java.util.Scanner;
public class DressEmInVests {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int x = scanner.nextInt();
int y = scanner.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i < n + 1; i++) {
int temp = scanner.nextInt();
a[i] = temp;
}
int[] b = new int[m + 1];
for (int i = 1; i < m + 1; i++) {
int temp = scanner.nextInt();
b[i] = temp;
}
// result;
int numPairs = 0;
ArrayList<String> listResult = new ArrayList<>();
int i = 1;
int j = 1;
while ((i < n + 1) && (j < m + 1)) {
if (a[i] - x <= b[j] && b[j] <= a[i] + y) {
listResult.add(i + " " + j);
i++;
j++;
numPairs++;
} else {
if (a[i] + y < b[j]) {
i++;
} else {
j++;
}
}
}
System.out.println(numPairs);
for (String s : listResult) {
System.out.println(s);
}
}
}