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+=1)
  13. cin>>A[n];
  14. for(int m=0; m<M; m+=1){
  15. cin>>B[m];
  16. B[m]+=1;
  17. }
  18.  
  19. // 由小到大枚舉對變化量有影響的價格
  20. sort(A,A+N);
  21. sort(B,B+M);
  22. int n=0; //#seller
  23. int m=M; //#buyer
  24. int a=0, b=0;
  25. while( m>n ){
  26. int x=(b==M || a<N && A[a]<=B[b] )? A[a]:B[b];
  27. for( ; a<N && A[a]==x; a+=1)
  28. n+=1;
  29. for( ; b<M && B[b]==x; b+=1)
  30. m-=1;
  31. if( m<=n ){
  32. cout<<x;
  33. return 0;
  34. }
  35. }
  36. }
Success #stdin #stdout 0.01s 5264KB
stdin
3 4
110 90 120
100 80 120 10000
stdout
110