fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. import static java.lang.Integer.min;
  5.  
  6. /**
  7.  * Created by bugkiller on 27/01/18.
  8.  */
  9. class WarmHoles {
  10. static class FastReader
  11. {
  12.  
  13. public FastReader()
  14. {
  15. br = new BufferedReader(new
  16. }
  17.  
  18. String next()
  19. {
  20. while (st == null || !st.hasMoreElements())
  21. {
  22. try
  23. {
  24. st = new StringTokenizer(br.readLine());
  25. }
  26. catch (IOException e)
  27. {
  28. e.printStackTrace();
  29. }
  30. }
  31. return st.nextToken();
  32. }
  33.  
  34. int nextInt()
  35. {
  36. return Integer.parseInt(next());
  37. }
  38.  
  39. long nextLong()
  40. {
  41. return Long.parseLong(next());
  42. }
  43.  
  44. double nextDouble()
  45. {
  46. return Double.parseDouble(next());
  47. }
  48.  
  49. String nextLine()
  50. {
  51. String str = "";
  52. try
  53. {
  54. str = br.readLine();
  55. }
  56. catch (IOException e)
  57. {
  58. e.printStackTrace();
  59. }
  60. return str;
  61. }
  62. }
  63.  
  64. static int n,x,y;
  65. static int s[] = new int[100000];
  66. static int f[] = new int[100000];
  67. static int v[] = new int[100000];
  68. static int w[] = new int[100000];
  69. static final int MAX = (int)1e8;
  70. public static void main(String[] args) throws IOException {
  71. FastReader in =new FastReader();
  72. n = in.nextInt();
  73. x = in.nextInt();
  74. y = in.nextInt();
  75. for (int i = 0; i < n; i++) {
  76. s[i] = in.nextInt();
  77. f[i] = in.nextInt();
  78. }
  79. for (int i = 0; i < x; i++) {
  80. v[i] = in.nextInt();
  81. }
  82. for (int i = 0; i < y; i++) {
  83. w[i] = in.nextInt();
  84. }
  85. Arrays.sort(v);
  86. Arrays.sort(w);
  87. System.out.println(solve());
  88. }
  89.  
  90. private static int solve(){
  91. int totalTime = Integer.MAX_VALUE;
  92. for (int i = 0; i < n; i++) {
  93. int t1 = floor(s[i]);
  94. int t2 = ceil(f[i]);
  95. totalTime = min(totalTime, t2-t1+1);
  96. }
  97. return totalTime;
  98. }
  99.  
  100. public static int floor(int key) {
  101. int start = 0, end = v.length-1;
  102. while (start <= end) {
  103. int mid = (start + end) / 2;
  104. if (v[mid] <= key) {
  105. if(mid+1 == v.length || v[mid+1] > key)return v[mid];
  106. else{
  107. start = mid+1;
  108. }
  109. } else {
  110. end = mid - 1;
  111. }
  112. }
  113. if(v[start]>key)return -MAX;
  114. return v[start];
  115. }
  116.  
  117. public static int ceil(int key) {
  118. int start = 0, end = w.length-1;
  119. while (start <= end) {
  120. int mid = (start + end) / 2;
  121. if (w[mid] >= key) {
  122. if(mid==0 || w[mid-1]<key)return w[mid];
  123. else end = mid-1;
  124. } else {
  125. start = mid + 1;
  126. }
  127. }
  128. if(w[end]<key)return MAX;
  129. return w[end];
  130. }
  131. }
Success #stdin #stdout 0.09s 4575232KB
stdin
3 4 2
15 21
5 10
7 25
4 14 25 2
13 21
stdout
8