fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.util.Arrays;
  6. import java.util.StringTokenizer;
  7.  
  8.  
  9.  
  10.  
  11. class PICAD {
  12.  
  13. public static void main(String[] args) throws IOException {
  14. // TODO Auto-generated method stub
  15. StringBuilder sb=new StringBuilder();
  16. for(int j=0;j<10;j++){
  17. //while(true){
  18. String s=br.readLine().trim();
  19. if(s.equals("") || s==null )break;
  20. int start=Integer.parseInt(stk.nextToken());
  21. int end=Integer.parseInt(stk.nextToken());
  22. int n=Integer.parseInt(br.readLine().trim());
  23. Time times[]=new Time[2*n];
  24. for(int i=0;i<times.length;){
  25. stk=new StringTokenizer(br.readLine().trim());
  26. times[i++]=new Time(Integer.parseInt(stk.nextToken()),i,'a');
  27. times[i++]=new Time(Integer.parseInt(stk.nextToken()),i,'d');
  28. }
  29. Arrays.sort(times);
  30. //System.out.println(Arrays.toString(times));
  31. int min_count=Integer.MAX_VALUE,max_count=Integer.MIN_VALUE,count=0,prev_time=-1;char prev_state='d';
  32. for(int i=0;i<times.length;i++){
  33. if(times[i].time>=start && times[i].time<=end){
  34. if(i!=0){
  35. max_count=Math.max(max_count, count);
  36. if((prev_time==times[i].time && prev_state!=times[i].state) || prev_time!=times[i].time)
  37.  
  38. min_count=Math.min(min_count, count);
  39. }
  40. }
  41. if( times[i].state=='a')
  42. count++;
  43. else if( times[i].state=='d')
  44. count--;
  45. prev_time=times[i].time;
  46. prev_state=times[i].state;
  47. //System.out.println(min_count+" "+max_count);
  48. }
  49. if(max_count==Integer.MIN_VALUE)max_count=0;
  50. if(min_count==Integer.MAX_VALUE)min_count=0;
  51. sb.append(min_count+" "+max_count+"\n");
  52. }
  53. pr.write(sb.toString());
  54. pr.flush();}
  55. static class Time implements Comparable<Time>{
  56. public Time(int nextInt, int i,char state) {
  57. time=nextInt;
  58. index=i;
  59. this.state=state;
  60. // TODO Auto-generated constructor stub
  61. }
  62. public Time(){}
  63. int time,index;
  64. char state;
  65. @Override
  66. public String toString() {
  67. // TODO Auto-generated method stub
  68. return index+"-"+time+"-"+state;
  69. }
  70. @Override
  71. public int compareTo(Time o) {
  72. // TODO Auto-generated method stub
  73. if(this.time==o.time){
  74. return this.state-o.state;
  75. }
  76. return this.time-o.time;
  77. }
  78. }
  79. }
  80. /*
  81. 5 20
  82. 3
  83. 5 20
  84. 5 10
  85. 11 20
  86. */
Success #stdin #stdout 0.07s 380224KB
stdin
0 0
1
0 0
5 5
3
2 4
2 5
2 6
5 555
7
2 3
4 4
5 5
77 77
66 333
60 77
60 70
5 8
4
5 8
5 8
5 8
5 8
5 8
4
4 4
4 5
6 7
8 9
5 8
4
5 6
5 33
4 5
8 8
6 6
3
2 77
2 5
6 6
7 99
3
0 6
100 200
150 300
9 14
4
8 10
8 12
12 14
12 14
0 4
9
1 1
2 2
0 3
4 4
0 1
1 3
2 2
0 0
1 3

stdout
1 1
2 2
0 3
4 4
0 1
1 3
1 2
0 0
1 3
0 5