ACM数学搭配问题 40

AssignmentsInafactory,thereareNworkerstofinishtwotypesoftasks(AandB).EachtypehasNtask... Assignments
In a factory, there are N workers to finish two types of tasks (A and B). Each type has N tasks. Each task of type A needs xi time to finish, and each task of type B needs yj time to finish, now, you, as the boss of the factory, need to make an assignment, which makes sure that every worker could get two tasks, one in type A and one in type B, and, what's more, every worker should have task to work with and every task has to be assigned. However, you need to pay extra money to workers who work over the standard working hours, according to the company's rule. The calculation method is described as follow: if someone’ working hour t is more than the standard working hour T, you should pay t-T to him. As a thrifty boss, you want know the minimum total of overtime pay.

Input
There are multiple test cases, in each test case there are 3 lines. First line there are two positive Integers, N (N<=1000) and T (T<=1000), indicating N workers, N task-A and N task-B, standard working hour T. Each of the next two lines has N positive Integers; the first line indicates the needed time for task A1, A2…An (Ai<=1000), and the second line is for B1, B2…Bn (Bi<=1000).

Output
For each test case output the minimum Overtime wages by an integer in one line.

Sample Input
2 5
4 2
3 5
Sample Output
4
展开
let4_go
2010-11-15 · TA获得超过169个赞
知道大有可为答主
回答量:85
采纳率:0%
帮助的人:59.6万
展开全部
第35届亚洲区哈尔滨站最水的一道题 - -*
一种类型的工作时间升序排列,另一种降序排列
对应相加,大于标准工作时间的,另存SUM++;
#include"iostream"
#include"algorithm"
#include"cstdio"
using namespace std;
int cmp(const int &a,const int &b)
{
if(a>b)
return 1;
return 0;
}
int main()
{
int a[1001],b[1001],i,n,t,s;
while(scanf("%d%d",&n,&t)==2)
{
s=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+n,cmp);
for(i=0;i<n;i++)
if(a[i]+b[i]-t>0)
s+=a[i]+b[i]-t;
cout<<s<<endl;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式