Task
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 < x i <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
题目大意:公司有n台机器(每台机器有工作时间x,
和最大能完成任务的难度系数y,且一台机器一天最
多只能完成一个任务),m个任务(每个任务有完
成需要的时间x,和难度系数y),问一天最多能完
成多少个任务,并且公司可以得到最多的钱数
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node{
int x,y;
};
node ta[100005],ma[100005]; //可以这样定义
long long int sum;
int num;
bool cmp(node a,node b)
{
if(a.x>b.x || a.x==b.x && a.y>b.y)
return 1;
else
return 0;
}
int main()
{
int n,m;
int v[105];
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(v,0,sizeof(v));
int i,j,k;
for(i=0;i<n;i++)
scanf("%d %d",&ma[i].x,&ma[i].y);
for(i=0;i<m;i++)
scanf("%d %d",&ta[i].x,&ta[i].y);
sort(ma,ma+n,cmp);
sort(ta,ta+m,cmp);
sum=0;
num=0;
j=0;
for(i=0;i<m;i++)
{
while(j<n && ma[j].x>=ta[i].x) //一台机器一天只能完成一个任务
{
v[ma[j].y]++;
j++;
} //选出所有可以完成这个任务的机器
for(k=ta[i].y;k<=100;k++) //选出能解决这个任务的最小水平k
{
if(v[k]) //先加入的机器在时间上肯定能满足后面的任务;
{
num++;
sum+=(500*ta[i].x+2*ta[i].y);
v[k]--;
break;
}
}
}
printf("%d %lld\n",num,sum);
}
return 0;
}