forked from pranavanurag/SPOJSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFASHION.cpp
More file actions
60 lines (49 loc) · 874 Bytes
/
Copy pathFASHION.cpp
File metadata and controls
60 lines (49 loc) · 874 Bytes
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
60
#include <iostream>
using namespace std;
int Partition(int A[], int Start, int End)
{
int Pivot = A[End];
int PartitionIndex = Start;
for(int i=Start; i<End; i++)
if(A[i]<=Pivot)
{
int temp = A[i];
A[i] = A[PartitionIndex];
A[PartitionIndex] = temp;
PartitionIndex+=1;
}
int temp = A[PartitionIndex];
A[PartitionIndex] = A[End];
A[End] = temp;
return PartitionIndex;
}
void QuickSort(int A[], int Start, int End)
{
if(Start<End)
{
int Q = Partition(A, Start, End);
QuickSort(A, Q+1, End);
QuickSort(A, Start, Q-1);
}
}
int main()
{
int t, n, X[1001], Y[1001];
long Score=0;
cin>>t;
while(t--&&t>=0)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>X[i];
for(int i=0;i<n;i++)
cin>>Y[i];
QuickSort(X, 0, n-1);
QuickSort(Y, 0, n-1);
for(int i=0;i<n;i++)
Score+=X[i]*Y[i];
cout<<Score<<endl;
Score=0;
}
return 0;
}