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