fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=2e5;
  5. const int MaxA=1e9;
  6. int N,M;
  7. int A[MaxN];
  8. int B[MaxN];
  9.  
  10. int main() {
  11. cin>>N>>M;
  12. for(int n=0; n<N; n++){
  13. cin>>A[n];
  14. }
  15. for(int m=0; m<M; m++){
  16. cin>>B[m];
  17. B[m]++;
  18. }
  19. sort(A,A+N);
  20. sort(B,B+M);
  21. int n=0;
  22. int m=M;
  23. int a=0,b=0;
  24. while(m>n){
  25. int x=(b==M || a<N && A[a]<=B[b])? A[a]:B[b];
  26. for(; a<N && A[a]==x; a++)
  27. n++;
  28. for(; b<N && B[b]==x; b++)
  29. m--;
  30. if(m<=n){
  31. cout<<x;
  32. return 0;
  33. }
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5304KB
stdin
3 4
110 90 120
100 80 120 10000
stdout
110