fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5. import java.util.StringTokenizer;
  6.  
  7. class Main
  8. {
  9. static class FastReader
  10. {
  11.  
  12. public FastReader()
  13. {
  14. br = new BufferedReader(new
  15. }
  16.  
  17. String next()
  18. {
  19. while (st == null || !st.hasMoreElements())
  20. {
  21. try
  22. {
  23. st = new StringTokenizer(br.readLine());
  24. }
  25. catch (IOException e)
  26. {
  27. e.printStackTrace();
  28. }
  29. }
  30. return st.nextToken();
  31. }
  32.  
  33. int nextInt()
  34. {
  35. return Integer.parseInt(next());
  36. }
  37.  
  38. long nextLong()
  39. {
  40. return Long.parseLong(next());
  41. }
  42.  
  43. double nextDouble()
  44. {
  45. return Double.parseDouble(next());
  46. }
  47.  
  48. String nextLine()
  49. {
  50. String str = "";
  51. try
  52. {
  53. str = br.readLine();
  54. }
  55. catch (IOException e)
  56. {
  57. e.printStackTrace();
  58. }
  59. return str;
  60. }
  61. }
  62.  
  63. public static void main(String[] args)
  64. {
  65. FastReader in =new FastReader();
  66. int N = in.nextInt();
  67. int X = in.nextInt();
  68. int Y = in.nextInt();
  69. int[][] contest = new int[N][2];
  70. int[] V = new int[X], W = new int[Y];
  71. for(int i = 0;i<N;i++){
  72. contest[i][0] = in.nextInt();
  73. contest[i][1] = in.nextInt();
  74. }
  75. for(int i = 0; i< X; i++)V[i] = in.nextInt();
  76. for(int i = 0; i<Y;i++)W[i] = in.nextInt();
  77.  
  78. Arrays.sort(contest, new Comparator<int[]>(){
  79. public int compare(int[] i1, int[] i2){
  80. return Integer.compare(i1[0],i2[0]);
  81. }
  82. });
  83. Arrays.sort(V);
  84. Arrays.sort(W);
  85. int time = Integer.MAX_VALUE;
  86. for(int i = 0; i< N;i++){
  87. int start = contest[i][0];
  88. int end = contest[i][1];
  89. if(start < V[0] || end >W[Y-1])continue;
  90. start = lBound(V, start, 0, X-1);
  91. end = uBound(W, end, 0, Y-1);
  92. time = Math.min(time, end-start+1);
  93. }
  94. System.out.println(time);
  95. }
  96.  
  97. static int lBound(int[] V, int start, int l, int r){
  98. int mid = (l+r)/2;
  99. if(V[mid] <= start && (mid == V.length-1 || V[mid+1] >start))return V[mid];
  100. else if(mid < V.length-1 && V[mid+1] <= start)return lBound(V,start, mid+1, r);
  101. else return lBound(V, start, l,mid-1);
  102. }
  103.  
  104. static int uBound(int[] W, int end, int l, int r){
  105. int mid = (l+r)/2;
  106. if(W[mid] >= end && (mid == 0 || W[mid-1] < end))return W[mid];
  107. else if(mid > 0 && W[mid-1] >= end)return uBound(W,end,l,mid-1);
  108. else return uBound(W,end,mid+1,r);
  109. }
  110. }
Success #stdin #stdout 0.1s 27952KB
stdin
3 4 2
15 21
5 10
7 25
4 14 25 2
13 21
stdout
8