fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int pros[10001], cons[10001], P, C;
  5. int bid(int num) {
  6. return lower_bound(pros, pros+P, num) + C - lower_bound(cons, cons+C, num);
  7. }
  8.  
  9. int main() {
  10. int T;
  11. cin >> T;
  12. while(T--) {
  13. int L = 0, R, M1, M2;
  14. cin >> P;
  15. for(int i = 0; i < P; i++)
  16. cin >> pros[i];
  17. sort(pros, pros+P);
  18. cin >> C;
  19. for(int i = 0; i < C; i++)
  20. cin >> cons[i];
  21. sort(cons, cons+C);
  22. R = 1 + (cons[C-1] > pros[P-1] ? cons[C-1] : pros[P-1]);
  23. while(L < R) {
  24. M1 = (2*L+R)/3;
  25. M2 = (L+2*R)/3;
  26. cout << L << ", " << M1 << ", " << M2 << ", " << R << endl;
  27. if(bid(M1) < bid(M2))
  28. R = M2-1;
  29. else
  30. L = M1+1;
  31. }
  32. cout << L << endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
3 3
10 16 12
21 20 25
stdout
0, 8, 17, 26
0, 5, 10, 16
6, 9, 12, 16
6, 7, 9, 11
8, 9, 10, 11
10, 10, 10, 11
11