HDU-3661-Assignments
/*
Assignments
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1301 Accepted Submission(s): 599 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
2010 Asia Regional Harbin Recommend
lcy
题意:有两个长度为N(N<=1000)的序列A和B,
把两个序列中的共2N个数分为N组,
使得每组中的两个数分别来自A和B,
每组的分数等于max(0,组内两数之和-t),
问所有组的分数之和的最小值。 解法:贪心。将A B排序,A中最大的和B中最小的一组,
A中第二大的和B中第二小的一组,
以此类推。给出一个简单的证明:
若有两组(a0,b0),(a1,b1)满足a0>=a1&&b0>=b1,
这两组的得分为max(a0+b0-t,0)+max(a1+b1-t,0) >= max(a0+b1-t,0)+max(a1+b0-t,0)
即(a0,b1),(a1,b0)的得分,所以交换b0 b1之后可以使解更优。
*/
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 2600
int a[maxn],b[maxn];
bool cmp(const int &a,const int &b)
{
return a>b;
}
int main()
{
int N,T,i,sum;
while(~scanf("%d%d",&N,&T))
{
sum=;
for(i=; i<N; i++)
scanf("%d",&a[i]);
for(i=; i<N; i++)
scanf("%d",&b[i]);
sort(a,a+N);
sort(b,b+N,cmp);
for(i=; i<N; i++)
if(a[i]+b[i]>T)
sum+=a[i]+b[i]-T;
printf("%d\n",sum);
}
}
HDU-3661-Assignments的更多相关文章
- hdu 3661 Assignments (贪心)
Assignments Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 3661 Assignments(水题的解法)
题目 //最早看了有点云里雾里,看了解析才知道可以很简单的排序过 #include<stdio.h> #include<string.h> #include<algori ...
- HDU 3661 Assignments (水题,贪心)
题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- HDU 3667.Transportation 最小费用流
Transportation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 分水岭分割算法(watershed segmentation)的C++实现(法1)
运行环境:ubuntu16.04+Qt+opencv2.4.13 参考链接:http://blog.csdn.net/u010741471/article/details/45193521 water ...
- [置顶]
云端TensorFlow读取数据IO的高效方式
低效的IO方式 最近通过观察PAI平台上TensoFlow用户的运行情况,发现大家在数据IO这方面还是有比较大的困惑,主要是因为很多同学没有很好的理解本地执行TensorFlow代码和分布式云端执行T ...
- Hibernate中用left join(左外连接)查询映射中没有关联关系的两个表记录问题
一.问题背景 分账表split_summary结构如下: create table SPLIT_SUMMARY ( uuid VARCHAR2(32) not null, star_tdate VAR ...
- Elasticsearch安装配置和测试
官方教程:https://www.elastic.co/guide/en/elasticsearch/reference/master/_installation.html 中文教程:https:// ...
- Shell 关闭指定进程
例如要关闭jupyter-notebook这个进程: - | 说明:管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入. “ps -ef” 查看所有进程 “grep -v g ...
- 解决visual studio2017没有系统类和方法注释的问题
好几次碰到这种情况了,每次都得稍微查一查才能解决这个问题,相信也有不少人遇到这个问题,在对方法还不是很熟练的时候,将鼠标放置到方法上去,就会有信息提示是一件非常方便的事情,本文的解决方法同样适用于只显 ...
- python使用progressbar显示进度条
progressbar安装: pip install progressbar 用法一 # -*- coding=utf-8 -*- import time from progressbar impor ...
- ICE:slice语言常识整理
ICE:Slice语言(二)--源文件和词法规则: 文件命名 Slice的源文件以.ice为扩展名. 对于大小写不区分的系统(例如DOS),文件的扩展名可以大写,也可以小写,例如Cli ...
- (效果四)jst如何判断对象是否为空?
前言:在实现业务逻辑的过程中,很多工程师都会遇到需要判断一个对象,数组是否为空的情景,很多时候我们在请求数据的时候都需要判断请求的对象数据是否为空,如果直接使用,在数据请求为空时,控制台就会报错.因此 ...
- opengl去除控制台黑窗口
增加如下语句: #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\ ...