Assignments

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2038    Accepted Submission(s): 1013

Problem Description
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
 
Source
 题意:(转)有两个长度为N(N<=1000)的序列A和B,把两个序列中的共2N个数分为N组,使得每组中的两个数分别来自A和B,每组的分数等于max(0,组内两数之和-t),问所有组的分数之和的最小值。
分析:贪心策略,将A,B排序,A中最大的和B中最小的一组,即将A升序排序,将B降序排序,这样便是最优解。。。
 #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn =1e3+;
int a[maxn],b[maxn];
bool cmp(const int a,const int b){
return a>b;
}
int main(){
int n,t;
while(~scanf("%d%d",&n,&t)){
for( int i=; i<n; i++ ){
cin>>a[i];
}
for( int i=; i<n; i++ ){
cin>>b[i];
}
sort(a,a+n);
sort(b,b+n,cmp);
int ans=;
for(int i=; i<n; i++ ){
if(a[i]+b[i]>t) ans+=a[i]+b[i]-t;
}
cout<<ans<<endl;
}
return ;
}

Assignments---(贪心)的更多相关文章

  1. hdu 3661 Assignments (贪心)

    Assignments Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 3661 Assignments (水题,贪心)

    题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...

  3. Assignments

    Assignments Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. German Collegiate Programming Contest 2013-B:Booking(贪心)

        Booking Pierre is in great trouble today! He is responsible for managing the bookings for the AC ...

  5. sgu 195 New Year Bonus Grant【简单贪心】

    链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...

  6. 【网络流+贪心】Homework

    题目描述 Taro is a student of Ibaraki College of Prominent Computing. In this semester, he takes two cou ...

  7. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  8. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. bootstrap-table方法之:合并单元格

    方法一 通过mergeCells方法 演示地址:http://issues.wenzhixin.net.cn/bootstrap-table/methods/mergeCells.html Merge ...

  2. go在ubuntu下安装

    http://blog.csdn.net/Ceciiiilia/article/details/71483221 综合目前网站上的各种安装方法,找到如下简单配置(不会报错或者少报错…) (一)从官网安 ...

  3. 关于Discuz! X系列远程代码执行漏洞

    一.漏洞起源 突然有同事反馈,无法注册 看到这里不了解的同行估计一年懵逼,这里也是常用的漏洞攻击,可以肯定的是  badwords.php文件被修改了 ,可以查看这个文件内容 <?php $_C ...

  4. MATLAB 程序计算结果出现 复数(a+bi)问题

    存在对负数开根号的情况了: >> (0.777)^0.1 ans = 0.9751 >> ( ans = 0.6037 >> (0.777)^2.1 ans = 0 ...

  5. Git回滚代码到某个commit

    回退命令: $ git reset --hard HEAD^ 回退到上个版本$ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前 $ git rese ...

  6. moving-files-from-one-linux-server-to-another-using-scp

    https://www.tecmint.com/scp-commands-examples/ https://haydenjames.io/linux-securely-copy-files-usin ...

  7. Docker入门简记

    Docker的容器环境实际上是借助类Linux命名空间,将各种系统资源按照容器不同划分了不同的命名空间进行隔离,为各个进程提供独立的运行环境关键概念:容器,镜像两个概念一起看,镜像好比平常系统中的各个 ...

  8. 【Unity】微信支付SDK官方安卓Demo的使用问题

    Unity3d使用微信支付是属于APP内发起支付调用的情况,其本质上是在安卓项目上使用微信SDK,安卓项目开发完成后再导入到Unity中作为Unity插件使用,即Unity中C#调用安卓(Java)代 ...

  9. count(*)、count(1)和count(列名)的区别

    count(*).count(1)和count(列名)的区别 1.执行效果上:   l  count(*)包括了所有的列,相当于行数,在统计结果的时候,不会忽略列值为NULL l  count(1)包 ...

  10. 【数据库】——SQLite使用drop column删除表字段

    由于项目需求变更,我需要在sqlite的表中删除一个字段,通用的sql操作语句如下: alter table task drop column custom_fields; 结果数据库提示如下错误: ...