1 / 3
Jun 2017
#include<iostream>
#include<bits/stdc++.h>
#include<stdlib.h>
using namespace std;
int main()
{
 int t,n;
 cin>>t;
 while(t--)
 {
    cin>>n;
    int m[1000],w[1000],sum=0,i,j;
    for(i=0;i<n;i++)
    {
        cin>>m[i];
    }
    for(j=0;j<n;j++)
    {
        cin>>w[j];
     }
    sort(m,m+n);
    sort(w,w+n);

    for(i=0;i<n;i++)
    {
        m[i]*=w[i];
         sum+=m[i];
       }
    cout<<sum<<endl;
   }
 return 0;
}

I am a newbie at SPOJ.Any help would be appreciated.

  • created

    Jun '17
  • last reply

    Jun '17
  • 2

    replies

  • 1.1k

    views

  • 2

    users

there is nothing wrong with your code.
i submitted your code and it was accepted.

YEAH i submitted it later and got AC.Don't know why it was giving WA before.Thanks for your time.