fork(1) download
  1. #include<stdio.h>
  2. int cmp(const void *a,const void *b)
  3. {
  4. return *(int *)a-*(int *)b;
  5. }
  6. /* void bubble(int a[],int b){// sorting here
  7.   int c,d,e;
  8.   for(c=0;c<b;c++){
  9.   for(d=0;d<b-c;d++){
  10.   if(a[d]>a[d+1]){
  11.   e=a[d];
  12.   a[d]=a[d+1];
  13.   a[d+1]=e;
  14.   }
  15.   }
  16.   }
  17.   }*/
  18. int main(){
  19. int a[100],b[100],d,e,f,g,m,n;
  20. scanf("%d",&d);
  21. while(d--){//testcases
  22. scanf("%d",&f);
  23. for(e=0;e<f;e++){// input array 1
  24. scanf("%d",&a[e]);
  25. }
  26. //bubble(a,f);
  27. for(e=0;e<f;e++)// input array 2
  28. scanf("%d",&b[e]);
  29. ///bubble(b,f);
  30.  
  31. qsort(a,f,sizeof(int),cmp);
  32. qsort(b,f,sizeof(int),cmp);
  33. /* for(e=0;e<f;e++)
  34.   {
  35.   printf("%d %d\n",a[e],b[e]);
  36.   }*/
  37. g=0;// logic starts here
  38. m=0;
  39. n=0;
  40. while(n<f){
  41. if(a[m]<=b[n]){
  42. g++;
  43. m++;
  44. n++;
  45. }
  46. else
  47. n++;
  48. }
  49.  
  50. printf("%d\n",g);
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 1792KB
stdin
2
3
10 30 20
30 10 20
5
9 7 16 4 8
8 3 14 10 10
stdout
3
4