fork download
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int T;
    cin>>T;

    while( T-- )
    {
       int n,m;
       vector<int> v1,v2;
       cin>>n>>m;

       for( int i=0;i<n;i++)
       {
           int temp;
           cin>>temp;
           v1.push_back(temp);
       }

       for( int i=0;i<m;i++)
       {
           int temp;
           cin>>temp;
           v2.push_back(temp);
       }

       sort(v1.begin(),v1.end());
       sort(v2.begin(),v2.end());

       reverse(v1.begin(),v1.end());
       reverse(v2.begin(),v2.end());

       long long count=0;
       int mn = min(m,n);
       for(int i=0;i<mn;i++)
            count += (v1[i] * v2[i]);
        cout<<count<<endl;
    }


    return 0;
}
Success #stdin #stdout 0s 15240KB
stdin
1
6 4
11 5 3 1 4 7
50 200 100 1000
stdout
13100