-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path531.java
More file actions
43 lines (40 loc) · 1.01 KB
/
531.java
File metadata and controls
43 lines (40 loc) · 1.01 KB
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
import java.util.*;
import java.io.*;
class A implements Comparable<A>{
int x, y;
public A (int x1, int y1){
this.x = x1; this.y = y1;
}
public int compareTo (A e) {
return this.x == e.x ? this.y - e.y : this.x - e.x;
}
}
public class Solution {
final static int N = 200010;
public static void main(String[] args) {
int [] a = new int [N];
int [] b = new int [N];
TreeSet<A> S = new TreeSet<A> ();
Scanner in = new Scanner (new BufferedInputStream (System.in));
int n, d;
n = in.nextInt (); d = in.nextInt ();
S.add(new A(-1000000000, -1));
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt (); b[i] = in.nextInt ();
S.add (new A (b[i], i));
}
int besta = -1, bestb = -1, ma = -1;
for (int i = 1, j = 1; i <= n; ++i) {
for (; j <= n && a[j] - a[i] < d; ++j) {
S.remove (new A (b[j], j));
}
if (S.isEmpty()) break;
else if (S.last ().x + b[i] > ma) {
ma = S.last ().x + b[i];
besta = i;
bestb = S.last ().y;
}
}
System.out.printf ("%d %d\n", besta, bestb);
}
}