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 N = Integer.parseInt(bf.readLine());
pair[] x = new pair[N];
pair[] temps = new pair[N];
for(int i = 0; i < N; i++){
StringTokenizer stk = new StringTokenizer(bf.readLine());
int a = Integer.parseInt(stk.nextToken());
int b = Integer.parseInt(stk.nextToken());
temps[i] = new pair(a, b);
}
x[N-1] = new pair(1, temps[N-1].y);
for(int i = N-2; i >= 0; i--){
int match = match(temps[i], temps[i+1], x[i+1]);
if(match != -1)x[i] = new pair(x[i+1].x+1, match);
else x[i] = new pair(1, temps[i].y);
}
int answer = 0;
for(int i = 0; i < N; i++) answer = Math.max(answer, x[i].x);
System.out.println(answer);
}
public static int match(pair p1, pair p2, pair x){
//p1 = temp[i]
//p2 = temp[i+1]
//x = x[i+1]
if(p1.x <= x.y && x.y <= p1.y) return x.y;
if(p1.y <= x.y)return p1.y;
return -1;
}
public static class pair{
int x, y;
public pair(int a, int b){
x = a;
y = b;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
8868 KB |
Output is correct |
2 |
Incorrect |
74 ms |
8556 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8560 KB |
Output is correct |
2 |
Correct |
76 ms |
8432 KB |
Output is correct |
3 |
Correct |
74 ms |
8684 KB |
Output is correct |
4 |
Incorrect |
74 ms |
8556 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
14320 KB |
Output is correct |
2 |
Correct |
277 ms |
14260 KB |
Output is correct |
3 |
Incorrect |
350 ms |
14296 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
548 ms |
43008 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
759 ms |
62296 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
806 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
798 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
849 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
708 ms |
62180 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
690 ms |
60704 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
741 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
792 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |