Created
March 29, 2014 16:29
-
-
Save nazarov-yuriy/9857559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class p1203 { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
PrintWriter out = new PrintWriter(System.out); | |
int n = in.nextInt(); | |
int[] count = new int[30003]; | |
TreeSet<Integer>[] starts = new TreeSet[30003]; | |
for (int i = 0; i < n; i++) { | |
int start = in.nextInt(); | |
int end = in.nextInt(); | |
if(starts[end] == null) | |
starts[end] = new TreeSet<Integer>(); | |
starts[end].add(start); | |
} | |
count[0] = 0; | |
for(int i=1;i<30003;i++){ | |
if(starts[i-1] != null){ | |
int c = count[i-1]; | |
for (Integer j : starts[i-1]) { | |
int from = j.intValue(); | |
if (count[from]+1 > c){ | |
c = count[from]+1; | |
} | |
} | |
count[i] = c; | |
} | |
else{ | |
count[i] = count[i-1]; | |
} | |
} | |
out.print( count[30002] ); | |
out.flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment