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;
  24. int b=0;
  25. while(m>n){
  26. int x=(a<N || b<M && A[a]<=B[b])?A[a]:B[b];
  27. for(;a<N && A[a]==x;a++)
  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.  
  37. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty