fork download
  1. #include<vector>
  2. #include<algorithm>
  3. #include<iostream>
  4. using namespace std;
  5. int main(){
  6. int t;cin>>t;
  7. while(t--){
  8. int n;cin>>n;
  9. vector<int>weight;vector<int>pies;
  10. for(int i=0;i<n;i++){
  11. int c;cin>>c;pies.push_back(c);
  12. }
  13. for(int i=0;i<n;i++){
  14. int c;cin>>c;weight.push_back(c);
  15. }
  16. sort(pies.begin(),pies.end());
  17. sort(weight.begin(),weight.end());
  18. int i=0,j=0;int count=0;
  19. while(i<n&&j<n){
  20. if(pies[i]<=weight[j]){
  21. i++;j++;
  22. count++;
  23. }else if(pies[i]>weight[j]){
  24. j++;
  25. }
  26.  
  27. }
  28. cout<<count<<endl;
  29. }
  30.  
  31. }
  32.  
Success #stdin #stdout 0s 3468KB
stdin
2
3
10 30 20
30 10 20
5
9 7 16 4 8
8 3 14 10 10
stdout
3
4