-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathairconditioned.java
More file actions
56 lines (42 loc) · 900 Bytes
/
airconditioned.java
File metadata and controls
56 lines (42 loc) · 900 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
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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class airconditioned {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int minions = scan.nextInt();
ArrayList<Range> ranges = new ArrayList<>();
while (minions --> 0)
ranges.add(new Range(scan.nextInt(), scan.nextInt()));
Collections.sort(ranges);
int room = ranges.get(0).y;
int count = 1;
for (Range r : ranges)
{
if (r.x <= room)
{
if (r.y < room)
room = r.y;
}
else
{
room = r.y;
count++;
}
}
System.out.println(count);
scan.close();
}
}
class Range implements Comparable<Range> {
int x , y;
public Range(int a , int b) {
x = a;
y = b;
}
public int compareTo(Range r) {
if (this.x == r.x)
return this.y - r.y;
return this.x - r.x;
}
}