UVA 11389 The Bus Driver Problem

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82842#problem/D

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 his total route length for a day exceeds d, he has to be paid overtime for every hour after the first d hours at a flat r taka / hour. Your task is to assign one morning route & one evening route to each bus driver so that the total overtime amount that the authority has to pay is minimized.

 

Input

The first line 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 are the lengths of the morning routes given in meters. Similarly the third line has n space separated integers denoting the evening route lengths. The lengths are positive integers less than or equal to 10000. The end of input is denoted by a case with three 0 s.

 

Output

For each test case, print the minimum possible overtime amount that the authority must pay.

 

Constraints

-           1 ≤ n ≤ 100

-           1 ≤ d ≤ 10000

-           1 ≤ r ≤ 5

 

Sample Input

Output for Sample Input

2 20 5

10 15

10 15

2 20 5

10 10

10 10

0 0 0

50

0

解题思路:这个题目的意思是怎样分配使公交车司机加班费减至最少,n个司机,早上走n条路径,每个路经是x长度,晚上走n条路径,每个路径是X长度,d表示一个司机一天固定要跑的长度,r表示价格,每超过y个长度,则司机可获得y*r的加班费。

要使加班费减到最低,则需要对上午所跑长度和下午所跑长度分别进行排序,一个从小到大,一个从大到小,这样二者之和均能降到最小,因此加班费也会控制到最小。

程序代码          :

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 
 5 using namespace std;
 6 const int m=100+5;
 7 int a[m],b[m];
 8 
 9 bool p(int a,int b)
10 {    return  a>b;}
11 
12 inline int max(int a,int b)
13 {
14     return a>b?a:b;
15 }
16 
17 int main()
18 {int n,d,r,i;
19     while(cin>>n>>d>>r&&(n!=0&&d!=0&&r!=0))
20     {
21         for(i=0;i<n;i++)
22             scanf("%d",&a[i]);
23 
24        for(i=0;i<n;i++)
25             scanf("%d",&b[i]);
26         sort(a,a+n);
27        sort(b,b+n,p);
28        int sum=0;
29         for(i=0;i<n;i++)
30             sum+=max(0,(a[i]+b[i]-d));
31         cout<<sum*r<<endl;
32     }
33    return 0;
34 }

 

转载于:https://www.cnblogs.com/www-cnxcy-com/p/4655464.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值