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
 

Author
FZU
 

Source

由于近日比赛卡一个貌似图论的贪心,故来补题~~

题意:有n个任务,每个任务有花费时间xi,等级yi;m个机器,每个机器有花费时间xi,等级yi。必须机器的时间和等级都不可以超过任务才可以完成这个任务。(这个地方读错题了QAQ,我以为时间是累加的,其实任务和机器都只能用一次)

做法:将任务和机器的结构体数组都按着先时间从大到小,再等级从大到小排序。(这个排序是根据等级最大到100,时间最大到1440来的,反过来的讲道理其实可以,但是貌似得TLE吧)然后用任务去匹配机器(就是最外层循环是任务)由于两个都是时间优先级最高,那么我们可以这么想,任务与机器的时间都是不递增的,现在可以匹配目前任务的机器也可以匹配以后的任务(只考虑时间这个因素),但是肯定不可以当前的这些机器随便选,我们遍历满足当前时间要求的机器,根据贪心的策略我们应该选择一个等级最小的来匹配……

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct machine
{
    int x,y;
}num1[100009];
struct task
{
    int x,y;
}num2[100009];
bool cmp1(machine a,machine b)
{
    if(a.x!=b.x)return a.x>b.x;
    return a.y>b.y;
}
bool cmp2(task a,task b)
{
    if(a.x!=b.x)return a.x>b.x;
    return a.y>b.y;
}
int val[100005];
int main()
{
  //  freopen("cin.txt","r",stdin);
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=0;i<n;i++)scanf("%d%d",&num1[i].x,&num1[i].y);
        for(int i=0;i<m;i++)scanf("%d%d",&num2[i].x,&num2[i].y);
        sort(num1,num1+n,cmp1);
        sort(num2,num2+m,cmp2);
        memset(val,0,sizeof(val));
      //  for(int i=0;i<n;i++)printf("machine:i=%d,x=%d,y=%d\n",i,num1[i].x,num1[i].y);
      //  for(int i=0;i<m;i++)printf("tasks:i=%d,x=%d,y=%d\n",i,num2[i].x,num2[i].y);
        int cnt=0,j=0;
        long long cntmoney=0;
        for(int i=0;i<m;i++)//task
        {
            while(j<n&&num1[j].x>=num2[i].x)
            {

                val[num1[j].y]++;
                j++;
            }
            for(int k=num2[i].y;k<=100;k++)
            {
                if(val[k])
                {
                    cnt++;
                    val[k]--;
                    cntmoney+=(500*num2[i].x+2*num2[i].y);
                    break;
                }
            }
        }
         printf("%d %I64d\n",cnt,cntmoney);
    }
    return 0;
}