11389-the Bus Driver Problem
Time limit:1.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=2384
In a city there are n bus drivers. Also There are n morning bus routes & N afternoon bus routes with various lengths. Each driver is assigned one morning Route & one evening route. For any driver, if him total route length for a day exceeds D, he has to is paid overtime for every hour after the Hours at a flat R taka/hour. Your task is to assign one morning Route & one evening route to all bus driver so this total overtime amount The authority has to pay is minimized.
Input
The "a" of each test case has three integers n, D and R, as described above. In the second line, there are n space separated integers which the are of the lengths morning. Similarly the third line has n space separated integers denoting the evening route. The lengths are positive integers less than or equal to 10000. The end of the input was denoted by a case with three 0 s.
Output
For each test case, print the minimum possible overtime amount the authority must.
Constraints
-1≤n≤100
-1≤d≤10000
-1≤r≤5
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Sample Input
2 20 5
10 15
10 15
2 20 5
10 10
10 10
0 0 0
Output for Sample Input
50
0
An increase of one minus is necessarily optimal, which can be disproved by exchanging the position of two elements.
Complete code:
/*0.016s*/
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace Std;
int a[105], b[105];
int main ()
{
int n, D, r, Sum, temp;
while (scanf ("%d%d%d", &n, &d, &r), N)
{for
(int i = 0; i < n; ++i)
scanf ("%d", &a[i]);
for (int i = 0; i < n; ++i)
scanf ("%d", &b[i]);
Sort (A, a + N);
Sort (b, B + N, greater<int> ());
sum = 0;
for (int i = 0; i < n; ++i)
{
temp = A[i] + b[i]-D;
if (temp > 0) sum + + temp;
}
printf ("%d\n", Sum * r);
}
return 0;
}
Author: csdn Synapse7