/*
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的更多相关文章

  1. hdu 3661 Assignments (贪心)

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

  2. hdu 3661 Assignments(水题的解法)

    题目 //最早看了有点云里雾里,看了解析才知道可以很简单的排序过 #include<stdio.h> #include<string.h> #include<algori ...

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

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

  4. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  5. HDU 3667.Transportation 最小费用流

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

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  10. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. sql密码修改

    首先,以window 认证登陆. 2 然后,在 安全性---->登录名---->sa.右击 选择属性.直接修改 星号密码即可. 3 然后 在右上角 文件--->链接对象资源管理器-- ...

  2. pcm ulaw alaw转换

    static byte ALawCompressTable[] = { 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 ...

  3. visual studio 菜单栏显示异常 插件安装异常 扩展异常修复

    这几天在使用Visual studio 的扩展插件的时候,遇见了菜单栏显示异常,解决方案显示异常的问题,如下: 经过自己的一顿摸索,解决方法如下,比如我在安装gitee或github插件之后就出现了这 ...

  4. notes on Art Pipeline

    Do not add complex clothes/facial hair to a model for Mixamo to auto rig, it will cause confusion. A ...

  5. iOS内存管理(objective-c)

    移动app开发中,由于移动设备内存的限制,内存管理是一个非常重要的话题.objective-c的内存管理,不仅是面试当中老生常谈的一个必问话题,也是日常项目开发中,特别需要重视的环节.对于笔者这种以j ...

  6. ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider

    // //  ViewController.m //  UI_Lesson3 // //  Created by archerzz on 15/8/13. //  Copyright (c) 2015 ...

  7. Oracle基本概念与数据导入

    Oracle基本概念 实例 一个Oracle实例(Oracle Instance)有一系列的后台进程(Backguound Processes)和内存结构(Memory Structures)组成.一 ...

  8. C++中的友元函数的总结

    1.友元函数的简单介绍 1.1为什么要使用友元函数 在实现类之间数据共享时,减少系统开销,提高效率.如果类A中的函数要访问类B中的成员(例如:智能指针类的实现),那么类A中该函数要是类B的友元函数.具 ...

  9. Cookie简单实例

    Cookie简单实例 1.创建CookieServlet package com.servlet.study; import java.io.IOException; import java.io.P ...

  10. 【DUBBO】dobbo的application的配置项

    Dubbo:application的配置项[一]:配置项 <dubbo:application name="服务名字" owner="拥有者" organ ...