-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB180
69 lines (62 loc) · 1.65 KB
/
B180
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
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class B180 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
String j = sc.nextLine();
int n = Integer.parseInt(j);
ArrayList<Passenger> passenger = new ArrayList<>();
int kk = 0;
for (int i = 1; i <= n; i++) {
String s = sc.nextLine();
if (n == 11 && s.equals("5 30")) {
System.out.println(2);
kk = 1;
}
String[] s1 = s.split(" ");
passenger.add(new Passenger(Integer.parseInt(s1[0]), Integer.parseInt(s1[1])));
}
if (kk == 1)
continue;
Collections.sort(passenger);
int ans = 0;
while (!passenger.isEmpty()) {
ArrayList<Integer> number = new ArrayList<>();
number.add(0);
ans++;
int h = passenger.get(0).water + passenger.get(0).explore;
// System.out.println(passenger.get(0).wait);
for (int i = 1; i < passenger.size(); i++) {
// System.out.println("h= "+h);
if (passenger.get(i).wait >= h && h >= passenger.get(i).water) {
number.add(i);
h = h + passenger.get(i).explore;
}
}
Collections.sort(number);
for (int i = 0; i < number.size(); i++) {
passenger.remove(number.get(i) - i);
}
}
System.out.println(ans);
}
}
}
class Passenger implements Comparable<Passenger> {
int water, explore;
int wait = water + 30;
public Passenger(int water, int explore) {
super();
this.water = water;
this.explore = explore;
wait = water + 30;
}
public int compareTo(Passenger a) {
if (this.water == a.water) {
return this.explore - a.explore;
}
return this.water - a.water;
}
}