-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheGreatBall.java
43 lines (42 loc) · 943 Bytes
/
TheGreatBall.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
package ques;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class tw{
int a,b;
}
public class TheGreatBall {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0){
t--;
int n=Integer.parseInt(br.readLine());
ArrayList<tw> arr=new ArrayList<tw>();
for(int i=0;i<n;i++){
String[] s=br.readLine().split(" ");
tw x=new tw();
x.a=Integer.parseInt(s[0]);
x.b=1;
arr.add(x);
tw y=new tw();
y.a=Integer.parseInt(s[1]);
y.b=-1;
arr.add(y);
}
Collections.sort(arr, new Comparator<tw>(){
public int compare(tw t1,tw t2){
return t1.a-t2.a;
}
});
int count=0;
int max=0;
for(int i=0;i<arr.size();i++){
count+=arr.get(i).b;
if(count>max)
max=count;
}
System.out.println(max);
}
}
}