Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1159 Accepted Submission(s): 282
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.
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.
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
Author
FZU
Source
2014 Multi-University Training Contest 1
题意:n台机器,m个任务,每台机器一天只能做一个任务,每个任务只能由一台机器完成,每个任务有需要的时间,和任务难度,机器也有最大工作时间,和等级。
问,一天最大收益是多少 (每个任务的收益 = 500*xi + 2*yi)?
贪心的思想,2*yi 最大值为200 < 500 ; 所以任务难度对总的收益影响不如时间
机器,和任务都以时间由大到小排序,时间相同任务难度由大到小排序,从时间最大的任务开始查找,找到所有可以满足时间的机器,再在机器中找出大于任务难度的,等级最小的机器,累加的总和中
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int x , y ;
}p[100010] , q[100010];
bool cmp(node n,node m)
{
if(n.x == m.x)
return n.y > m.y ;
else
return n.x > m.x ;
}
int main()
{
int i , j , n , m , num ;
__int64 sum ;
int k[2000] ;
while(scanf("%d %d", &n, &m)!=EOF)
{
memset(k,0,sizeof(k));
num = 0 ;
sum = 0 ;
for(i = 0 ; i < n ; i++)
scanf("%d %d", &p[i].x, &p[i].y);
for(j = 0 ; j < m ; j++)
scanf("%d %d", &q[j].x, &q[j].y);
sort(p,p+n,cmp);
sort(q,q+m,cmp);
for(i = 0 , j = 0 ; j < m ; j++)
{
while(1)
{
if(i < n && p[i].x >= q[j].x)//机器最大时间大于任务时间,但不一定满足等级大于任务难度,可能存在在该机器的后面有满足任务时间也满足任务难度的
{
k[ p[i].y ]++ ;
i++ ;
}
else
break;
}
for(int t = q[j].y ; t <= 100 ; t++)
{
if( k[ t ] )
{
num++ ;
sum += ( q[j].x*500 + q[j].y*2 ) ;
k[t]-- ;
break;
}
}
}
printf("%d %I64d\n", num, sum);
}
return 0;
}