forked from mintuhouse/spoj-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10442-cadydist.cpp
41 lines (39 loc) · 978 Bytes
/
10442-cadydist.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
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int lesst (const void * a, const void * b){
return (( *(long long*)a - *(long long*)b )<0);
}
int greatt (const void * a, const void * b){
return (( *(long long*)b - *(long long*)a )<0);
}
int main(){
long long N,c,p,t,cz,pz;
long long C[100001];
long long P[100001];
for(int i=0;i<=100000;i++){ C[i]=0; P[i]=0; }
scanf("%lld",&N);
while(N!=0){
t=0,cz=0;pz=0;
for(int i=0;i<N;i++){
scanf("%lld",&c);
C[cz++]=c;
}
for(int i=0;i<N;i++){
scanf("%lld",&p);
P[pz++]=p;
}
qsort(C,cz,sizeof(long long),lesst);
qsort(P,pz,sizeof(long long),greatt);
for(int i=0;i<cz;i++){
//cout<<P[i]<<" "<<C[i]<<endl;
t+=C[i]*P[i];
C[i]=0;
P[i]=0;
}
printf("%lld\n",t);
scanf("%lld",&N);
}
return 0;
}