寒假训练补题-第九天--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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值