Problem Description
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.

Input
The input contains several test cases. 
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.

Output
For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.

Sample Input
1 2 100 3 100 2 100 1

Sample Output
1 50004

题目:一家公司有m个任务需要完成,每件任务有一个最少工作时间和一个任务难度,同时这家公司一共有n台机器,每台对应一个最大工作时间和机器的等级,用这n台机器来完成任务。每台机器每天能完成一件任务----这件任务的需要的工作时间和任务难度分别要不超过机器的最长工作时间和机器的等级,每完成一件任务,公司获得500*任务工作时间+2*任务等级的利润。给定这些任务和机器的详细情况,问最多能完成多少件任务,利润是多少?(多种情况时输出最大利润)

题解的意思就是----每完成一件任务,获得利润=500*t+2*w,这里w的范围是1-100,最大值W=200<500对于整体利润的影响很小,所以对任务和时间均按照t递减排序,t相同按照w递减排序。然后从第一件任务开始遍历,找出所有能够解决这项任务的机器,并挑出工作时间最少,并且等级最低的那台来完成这项任务,以此类推,直到所有任务都完成。

为什么要这样安排呢?任务排序之后,后边的任务的一部分是时间与当前任务时间相同,但任务等级低的,能过解决当前任务的机器比人能够完成剩下的任务;另外一部分是时间比当前任务短,任务等级比当前任务高的,假设我挑走一台等级高机器,这台机器能完成这两项任务,另外存在一台机器等级低的机器只能完成当前任务,如果我用等级高的那台来完成当前任务的话,后来的任务就不能完成了,所以我要选择等级低但是能完成当前任务的那台机器;第三种情况,时间短,任务等级低的,能够完成当前任务的那些机器必然能用来完成这些任务。

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
struct node
{
int x,y;
}s1[100005],s2[100005];
int cmp(node a,node b)
{
if(a.x == b.x)
return a.y>b.y;
return a.x>b.x;
}
int main()
{
int n,m,i,j,x,k;
long long sum;
while(~scanf("%d%d",&n,&m)){
x = sum = 0;
int c[101] = {0};
for(i = 0; i<n; i++){
scanf("%d%d",&s1[i].x,&s1[i].y);
}
for(i = 0; i<m; i++){
scanf("%d%d",&s2[i].x,&s2[i].y);
}
sort(s1,s1+n,cmp);
sort(s2,s2+m,cmp);
for(i = 0,j = 0; i<m; i++){
while(j<n && s1[j].x >= s2[i].x){ //将所有时间符合的都挑出来
c[s1[j].y]++;
j++;
}
for(k = s2[i].y; k <= 100; k++){ //从符合时间的里面挑出等级最低的一台来完成任务
if(c[k]){
c[k]--;
sum += (s2[i].x*500+s2[i].y*2);
x++;
break;
}
}
}
cout<<x<<" "<<sum<<endl;
}
return 0;
}

  

最新文章

  1. Pyunit测试框架
  2. 解决64位Windows2003程序字体很小的问题
  3. Visual Studio 2015官方汇总包括下载和视频
  4. 一步一步学习Swift之(四)玩转UIWebView
  5. 转:PHP Composer 管理工具的介绍 这个相对清晰点
  6. FTP服务器移动文件目录
  7. UML类图的6中关系
  8. 计算1到n整数中,字符ch出现的次数
  9. 揭开Html 标签的面纱,忘不了的html .
  10. css中position中的几个属性
  11. 如何把程序钉到Windows7任务栏(修正版)
  12. markdown绘图插件----mermaid简介
  13. mysql8.0卸载干净--win10
  14. Docker镜像加速器配置
  15. SharePoint 2010 安装错误:请重新启动计算机,然后运行安装程序以继续
  16. Docker Client (another java docker client api)
  17. Win10系列:C#应用控件基础17
  18. ARM板移植udev-126
  19. 一定要 先删除 sc表 中的 某元组 行,,, 再删除 course表中的 元组行
  20. Oracle PLSQL Demo - 08.定义显式游标[Define CURSOR, Open, Fetch, Close CURSOR]

热门文章

  1. 2019/04/06 BJ省选模拟DAY1
  2. 洛谷 P2042 【[NOI2005]维护数列】
  3. elasticsearch更改mapping(不停服务重建索引)
  4. C++中使用vector.erase()需要注意的事项
  5. Pack
  6. bzoj3051[WC2013]平面图(树上倍增+平面图转对偶图+扫描线)
  7. Java入门:基础算法之二进制转换为十进制
  8. 重置sqlserver自增长列的种子
  9. Quartz C#使用
  10. Webform——JQuery基础(选择器、事件、DOM操作)