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 ...
随机推荐
- java.lang.IllegalArgumentException: Invalid character found in method name
1.错误描述 信息: Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors ...
- 文本数据预处理:sklearn 中 CountVectorizer、TfidfTransformer 和 TfidfVectorizer
文本数据预处理的第一步通常是进行分词,分词后会进行向量化的操作.在介绍向量化之前,我们先来了解下词袋模型. 1.词袋模型(Bag of words,简称 BoW ) 词袋模型假设我们不考虑文本中词与词 ...
- IOS开发 清空数组正确方法
NSArray以及NSMutableArray 在Objc中的两种数组(不可变数组和可变数组), 在日常开发中,经常会遇到需要清空数组的情况,很多人下意识的会想到nil这个方法,这里是不提倡的.因为如 ...
- 关于鼠标不敏感导致自以为ubuntu很怪的问题
你要相信自己拥有的确实是一个垃圾鼠标,而不要以为复制和粘贴有感觉控制不住.
- z=sin(xy)
看了<千年难题>,第一章是黎曼猜想.里面有两个我很感兴趣的问题:一是关于函数的图形表示方式,比如z=sin(xy)的图像,二是大数的因子分解方式. 专业的数学软件应该能够很容易的生成各种函 ...
- BZOJ4036:按位或 (min_max容斥&高维前缀和)
Description 刚开始你有一个数字0,每一秒钟你会随机选择一个[0,2^n-1]的数字,与你手上的数字进行或(c++,c的|,pascal 的or)操作.选择数字i的概率是p[i].保证0&l ...
- BZOJ2761: [JLOI2011]不重复数字【set】【傻逼题】
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- Vim-Go环境搭建
Vim-Go环境搭建 https://www.cnblogs.com/qcloud1001/p/10072325.html https://www.cnblogs.com/chris-cp/p/584 ...
- PHP和JS页面跳转和刷新总结
PHP 页面跳转: // 只是跳转,所以一定要用die();或者exit;终止下一步操作; header('location:index.php'); exit; // 等待3秒,跳转并刷新 head ...
- 定义文档兼容性、让IE按指定版本解析我们的页面
http://blog.useasp.net/archive/2013/05/29/x-UA-compatible-defining-document-compatibility-emulate-ie ...