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<>();
set.add(min[0]);
map.put(min[0], 1);
int left = 0, right = 0;
int answer = 0;
while(right < N){
int highestmin = set.last();
if(min[right+1]>=highestmin||highestmin<=max[right+1]){
right++;
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{
if(right==left){
right++;
left++;
set.remove(min[left-1]);
map.remove(min[left-1]);
set.add(min[left]);
map.put(min[left], 1);
}
else{
left++;
map.replace(min[left-1], map.get(min[left-1])-1);
if(map.get(min[left-1])==0){
set.remove(min[left-1]);
map.remove(min[left-1]);
}
}
}
answer = Math.max(answer, right-left+1);
}
System.out.println(answer);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
17388 KB |
Output is correct |
2 |
Correct |
89 ms |
17644 KB |
Output is correct |
3 |
Correct |
90 ms |
17488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
17384 KB |
Output is correct |
2 |
Correct |
84 ms |
17500 KB |
Output is correct |
3 |
Correct |
91 ms |
17516 KB |
Output is correct |
4 |
Correct |
90 ms |
17644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
31104 KB |
Output is correct |
2 |
Incorrect |
354 ms |
22628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1054 ms |
35220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
34676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
33292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1065 ms |
32176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
39208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
848 ms |
28200 KB |
Output is correct |
2 |
Correct |
849 ms |
28184 KB |
Output is correct |
3 |
Incorrect |
581 ms |
30396 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1006 ms |
36708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1093 ms |
51848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
34940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |