-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11389.java
55 lines (40 loc) · 997 Bytes
/
11389.java
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
/*
* UVa 11389: The Bus Driver Problem
*
* Problem Statement: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2384
*/
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int d = scan.nextInt();
int r = scan.nextInt();
int[] morning, evening;
while (n > 0 && d > 0 && r > 0) {
// route lengths
morning = new int[n];
evening = new int[n];
for (int i = 0; i < n; i++) {
morning[i] = scan.nextInt();
}
Arrays.sort(morning);
for (int i = 0; i < n; i++) {
evening[i] = scan.nextInt();
}
Arrays.sort(evening);
int o = 0;
for (int i = 0; i < n; i++) {
int h = morning[i] + evening[n - (i + 1)];
if (h > d) {
o += (h - d);
}
}
System.out.println(o * r);
n = scan.nextInt();
d = scan.nextInt();
r = scan.nextInt();
}
}
}