fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class test
  5. {
  6. public static void main(String args[]) throws IOException
  7. {
  8.  
  9. int t = Integer.parseInt(br.readLine());
  10.  
  11. for(int i=0;i<t;i++)
  12. {
  13. int n = Integer.parseInt(br.readLine());
  14. int left[] = new int[n];
  15. int right[] = new int[n];
  16. for(int j=0;j<n;j++)
  17. {
  18. String s[] = br.readLine().split(" ");
  19. int l = Integer.parseInt(s[0]);
  20. int r = Integer.parseInt(s[1]);
  21.  
  22. left[j] = l;
  23. right[j] = r;
  24. }
  25.  
  26. TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>();
  27. for(int k=0;k<n;k++)
  28. {
  29. tm.put(right[k],left[k]);
  30. }
  31. int flag=0;
  32. int back=-3;
  33. int front=-3;
  34. int count=1;
  35. for(int key: tm.keySet())
  36. {
  37. if(flag==0)
  38. { back = key;
  39. flag++;
  40. }
  41. else
  42. {
  43. front = key;
  44. if(tm.get(front)>back)
  45. {
  46. count++;
  47. back = front;
  48. }
  49.  
  50. }
  51. }
  52. System.out.println(count);
  53. }
  54.  
  55.  
  56. }
  57.  
  58. }
Runtime error #stdin #stdout #stderr 0.08s 380160KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:454)
	at java.lang.Integer.parseInt(Integer.java:527)
	at test.main(Main.java:11)