fork download
  1. #include<cstdio> //for scanf(), printf()
  2. #include<iostream>
  3. #include<algorithm> //for sorting
  4. using namespace std;
  5.  
  6. int main(){
  7. int t,n,i,w[30],l[30],tw=0,tl=0;
  8. int ans,j;
  9. cin>>t;
  10. while(t--!=0){
  11. cin>>n;
  12. /* as the array sizes are thirty (30) so indexing starts from 0 upto 29
  13. i.e., for(i=0;i<n;i++)
  14. but if indexing is to be started from 1 upto 30 than declare the array size as "31"
  15. */
  16. for(i=0;i<n;i++){
  17. scanf("%d",&w[i]);
  18. }
  19. for(i=0;i<n;i++){
  20. scanf("%d",&l[i]);
  21. }
  22.  
  23. /*
  24. for(i=1;i<=n;i++){
  25. tw=tw+w[i];
  26. tl=tl+l[i];
  27. }
  28. if(tw<=tl)
  29. cout<<n<<endl;
  30. else
  31. cout<<--n<<endl;
  32. */
  33.  
  34. // modified block
  35. std::stable_sort(l,l+n); // you can use any sorting method as long as it sorts in non-decreasing order
  36. std::stable_sort(w,w+n);
  37. ans=0;
  38. for(i=0,j=0;i<n && j < n; i++) {
  39. while(j < n && w[i]>l[j])
  40. j++;
  41. if (j<n) {
  42. ans++;
  43. j++;
  44. }
  45. }
  46. cout<<ans<<endl;
  47. }
  48. return(0);
  49. }
Success #stdin #stdout 0s 3236KB
stdin
3
3
10 30 20
30 10 20
5
9 7 16 4 8
8 3 14 10 10
3
10 100 100
20 30 40
stdout
3
4
1