-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVA11389.cpp
40 lines (40 loc) · 865 Bytes
/
UVA11389.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define swp(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
void sort(int array[],int n,int f){
int temp;
for (int i = 0; i < n-1; i++) {
for (int j = 1; j < n; j++) {
if (f) {
if (array[j] < array[j - 1])
swp(array[j], array[j - 1], temp);
}
else {
if (array[j] > array[j - 1])
swp(array[j], array[j - 1], temp);
}
}
}
}
int main()
{
int n, d, r,morn[150],afternoon[150];
while (scanf("%d %d %d", &n, &d, &r) != EOF && n) {
getchar();
for (int i = 0; i < n; i++)
scanf("%d", &morn[i]);
getchar();
for (int i = 0; i < n; i++)
scanf("%d", &afternoon[i]);
getchar();
sort(morn, n, 1);
sort(afternoon, n, 0);
int mini = 0;
for (int i = 0; i < n; i++) {
if (morn[i] + afternoon[i] > d)
mini += (morn[i] + afternoon[i] - d)*r;
}
printf("%d\n", mini);
}
}