-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10025.java
More file actions
41 lines (34 loc) · 1.23 KB
/
Copy pathBOJ_10025.java
File metadata and controls
41 lines (34 loc) · 1.23 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
// BOJ - 10025
// Problem Sheet - https://www.acmicpc.net/problem/10025
import java.util.*;
import java.io.*;
public class Main {
private static final int RANGE = 1_000_001;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int[] buckets = new int[RANGE];
int WINDOW_SIZE = 2 * K + 1;
int totalIce = 0;
for (int i=0 ; i<N ; i++) {
st = new StringTokenizer(br.readLine());
int g = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
buckets[x] = g;
if (x < WINDOW_SIZE) {
totalIce += g;
}
}
int maxIce = 0;
for (int i = 0; i<=Math.max(0, RANGE - WINDOW_SIZE) ; i++) {
maxIce = Math.max(maxIce, totalIce);
if (i + WINDOW_SIZE >= RANGE) break;
totalIce -= buckets[i];
totalIce += buckets[i + WINDOW_SIZE];
}
System.out.println(maxIce);
br.close();
}
}