SORT17


TEST CASE 1 

INPUT
2
3 
3 1 1
6 5 4
5
6 1 9 5 4
3 4 8 2 4
OUTPUT
23
80

TEST CASE 2 

INPUT
2
4
3 8 1 6
1 7 5 1
5
6 4 7 1 3
4 2 6 9 1
OUTPUT
36
62

#include <stdio.h>
void result(int a[],int b[],int n);
int main()
{
  int t, i, j, arr1[30], arr2[30], x, temp;
  scanf("%d",&t);
  while(t--)
  {
    scanf("%d",&x);
    for(i=0;i<x;i++)
    {
      scanf("%d",&arr1[i]);
    }
   
    for(i=0;i<x;++i)
    {
     for (j=i+1;j<x;++j)
      {
       if (arr1[i] > arr1[j])
        {
         temp = arr1[i];
         arr1[i] = arr1[j];
         arr1[j] = temp;
        }
      }
    }
   
    for(i=0;i<x;i++)
    {
      scanf("%d",&arr2[i]);
    }
   
    for(i=0;i<x;++i)
    {
     for (j=i+1;j<x;++j)
      {
       if (arr2[i] < arr2[j])
        {
         temp = arr2[i];
         arr2[i] = arr2[j];
         arr2[j] = temp;
        }
      }
    }
   
    result(arr1, arr2, x);
  }
  return 0;
}

void result(int a[],int b[],int n)
{
  int i, fin=0, sum;
  for(i=0;i<n;i++)
  {
      fin+=a[i]*b[i];
      sum=fin;
  }
  printf("%d\n",sum);
}

Comments

Popular posts from this blog

AR1

SER12

AR15