-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCADYDIST.cpp
More file actions
43 lines (39 loc) · 873 Bytes
/
CADYDIST.cpp
File metadata and controls
43 lines (39 loc) · 873 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
/* U need to find the possibly minimum total number of price
for class with maximum number students assign candy with minimum price
likewise for class with minimum number of students assign candy with maximum price
*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int compare1 (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int compare2 (const void * a, const void * b)
{
return ( *(int*)b - *(int*)a );
}
int main(void) {
long long t,x,sum,i;
while(1){
scanf("%lld",&t);
if(t==0)
break;
x=t;
long long a[x],b[x];
i=0;
while(t--)
scanf("%lld",&a[i++]);
i=0;
while(x--)
scanf("%lld",&b[i++]);
sum=0;
qsort((void*)a,i,sizeof(long long),compare1);
qsort((void*)b,i,sizeof(long long),compare2);
for(int k=0;k<i;k++)
sum+=a[k]*b[k];
printf("%lld\n",sum);
}
return 0;
}