#include<cstdio>
#include<iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)
#define S(N) scanf("%d", &N)
#define ST(a,N) sort(a, a+ N)
using namespace std;
int main()
{
int test, N, M, ans, i ,men[1001], women[1001];
S(test);
while (test--)
{
ans = 0;
S(N);
FOR(i,N)
S(men[i]);
FOR(i,N)
S(women[i]);
ST(men,N);
ST(women,N);
FOR(i,N)
ans += men[i] * women[i];
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)
#define S(N) scanf("%d", &N)
#define ST(a,N) sort(a, a+ N)
using namespace std;
int main()
{
int test, N, M, ans, i ,men[1001], women[1001];
S(test);
while (test--)
{
ans = 0;
S(N);
FOR(i,N)
S(men[i]);
FOR(i,N)
S(women[i]);
ST(men,N);
ST(women,N);
FOR(i,N)
ans += men[i] * women[i];
printf("%d\n", ans);
}
return 0;
}
No comments:
Post a Comment