import java.io.*;
import java.util.*;
public class tem {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader bf = new BufferedReader(new FileReader("tester.in"));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int[] min = new int[1000000];
int[] max = new int[1000000];
int N = Integer.parseInt(bf.readLine());
for(int i = 0; i < N; i++){
StringTokenizer stk = new StringTokenizer(bf.readLine());
min[i] = Integer.parseInt(stk.nextToken());
max[i] = Integer.parseInt(stk.nextToken());
}
TreeSet<Integer> set = new TreeSet<>();
HashMap<Integer, Integer> map = new HashMap<>();
int left = 0;
int right = 0;
int counter = 1;
int answer = 0;
set.add(min[0]);
map.put(min[0], 1);
while(right < N){
int highestmin = set.last();
if(min[right+1]>=highestmin||highestmin<=max[right+1]){
right++;
counter++;
if(set.contains(min[right]))map.replace(min[right], map.get(min[right])+1);
else{
set.add(min[right]);
map.put(min[right], 1);
}
}
else{
map.replace(min[left], map.get(min[left])-1);
if(map.get(min[left])==0){
set.remove(min[left]);
map.remove(min[left]);
}
counter--;
if(right==left){
right++;
counter = 1;
set.add(min[left+1]);
map.put(min[left+1], 1);
}
left++;
}
answer = Math.max(answer, counter);
}
System.out.println(answer);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
17624 KB |
Output is correct |
2 |
Correct |
84 ms |
17384 KB |
Output is correct |
3 |
Correct |
85 ms |
17388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
17360 KB |
Output is correct |
2 |
Correct |
87 ms |
17360 KB |
Output is correct |
3 |
Correct |
86 ms |
17388 KB |
Output is correct |
4 |
Correct |
84 ms |
17388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
28788 KB |
Output is correct |
2 |
Incorrect |
342 ms |
22668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
35544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
44664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
52280 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
32276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
52732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
857 ms |
33648 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
951 ms |
38936 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
47920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
44076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |