forked from mbobesic/algorithms-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimum-scalar-product.cpp
53 lines (41 loc) · 1.01 KB
/
minimum-scalar-product.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
// link: http://code.google.com/codejam/contest/32016/dashboard#s=p0
// name: Minimum Scalar Product
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int T;
FILE * inFile, * outFile;
inFile = fopen ("A-large-practice.in","r+");
outFile = fopen ("A-large-practice.out","w");
fscanf(inFile, "%d",&T);
for(int t=0;t<T;++t)
{
int n;
fscanf(inFile, "%d", &n);
vector<int> x, y;
for(int i=0;i<n;++i)
{
int xi;
fscanf(inFile,"%d",&xi);
x.push_back(xi);
}
for(int i=0;i<n;++i)
{
int yi;
fscanf(inFile,"%d",&yi);
y.push_back(yi);
}
sort(x.begin(),x.end());
sort(y.begin(),y.end());
long long result = 0;
for(int i=0;i<n;++i)
{
result += (long long) x[i]*y[n-i-1];
}
fprintf(outFile,"Case #%d: %lld\n", (t+1), result);
}
fclose(inFile);
fclose(outFile);
}