寒假训练补题-第九天--H8-贪心

In a city there are n bus drivers. Also there are n morning bus routes and n afternoon bus routes withvarious lengths. Each driver is assigned one morning route and 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 dhours at a flat r taka / hour. Your task is to assign one morning route and one evening route to each bus driver so that the total overtime amount that the authority has to pay is minimized.

在一个城市有n个公共汽车司机。此外,还有n条早间巴士路线和下午多条巴士路线。每位司机都分配了一条早晨路线和一条晚间路线。对于任何驾驶员,如果他一天的总路线长度超过d,则必须在第一小时后以平坦的塔卡/小时的每小时加班。您的任务是为每个公共汽车司机分配一条早晨路线和一条晚间路线,以便最大限度地减少当局必须支付的总加班费。

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.

输入
如上所述,每个测试用例的第一行具有三个整数n,d和r。在第二行中,有n个空格分隔的整数,它们是以米为单位的早晨路线的长度。类似地,第三行具有n个空格分隔的整数,表示晚间路线长度。长度是小于或等于10000的正整数。输入的结尾由具有三个0的情况表示。

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
2 20 5
10 15
10 15
2 20 5
10 10
10 10
0 0 0

Sample Output
50
0

ac代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
int mlen[110];
int alen[110];
int main()
{
	int d,n,r;
	while (scanf("%d%d%d", &n, &d, &r) == 3)
	{
		if (n == 0 && d == 0 && r == 0)
			break;
		int sum = 0;
		for (int i = 0; i < n; ++i)
			scanf("%d", &mlen[i]);
		for (int i = 0; i < n; ++i)
			scanf("%d", &alen[i]);
		sort(mlen, mlen + n);
		sort(alen, alen + n);
		for (int i = 0; i < n; ++i)
			if (mlen[i] + alen[n - 1 - i] > d)
				sum += mlen[i] + alen[n - 1 - i] - d;
		printf("%d\n", sum*r);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值