forked from Shubham28/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFASHION.cpp
59 lines (45 loc) · 828 Bytes
/
FASHION.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
#define FOR(A,B,cnt) for(int A=B;A<cnt;A++)
#define EFOR(A,B,cnt) for(int A=B;A<=cnt;A++)
#define RFOR(A,B,cnt) for(int A=B;A>=cnt;A--)
#define LL long long
using namespace std;
inline void Input(int &N)
{
int ch,sign;
N=0;
while((ch<'0' || ch>'9') && ch!='-' && ch!=EOF)
ch=getchar();
if(ch=='-')
sign=-1,ch=getchar();
else
sign=1;
do
N=(N<<3)+(N<<1)+(ch-'0');
while((ch=getchar())>='0' && ch<='9');
N*=sign;
return;
}
int main()
{
int T,N;
int men[1001],women[1001];
Input(T);
while(T--){
Input(N);
FOR(inp,0,N)
Input(men[inp]);
FOR(inp,0,N)
Input(women[inp]);
sort(men,men+N);
sort(women,women+N);
long ans=0;
FOR(all,0,N)
ans+=(men[all]*women[all]);
printf("%ld\n",ans);
}
return 0;
}