HDU 4086

来源:互联网 发布:声鉴软件 编辑:程序博客网 时间:2024/05/01 09:25

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864

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 2100 3100 2100 1
 

Sample Output
1 50004
#include<iostream>#include<algorithm>using namespace std;#define N 100001typedef struct{    int time,level;}task;task machine[N],work[N];bool compare(task a,task b){        if(a.time==b.time)            return a.level>b.level;        return a.time>b.time;}int main(){//    freopen("E:\\in.txt","r",stdin);    bool flag[N];    memset(flag,false,sizeof(flag));    int n,m,i,j,cnt;    __int64 money;    while(scanf("%d%d",&n,&m)==2){        int c[101]={0};        cnt=money=0;        for(i=0;i<n;i++)            cin>>machine[i].time>>machine[i].level;        for(i=0;i<m;i++)            cin>>work[i].time>>work[i].level;        sort(machine,machine+n,compare);        sort(work,work+m,compare);        for(i=0,j=0;i<m;i++){            while(j<n && machine[j].time>=work[i].time)              {                  c[machine[j].level]++;                  j++;              }              for(int k = work[i].level; k<=100; k++)              {                  if(c[k])                  {                      c[k]--;                      money+=(work[i].time*500+work[i].level*2);                      cnt++;                      break;                  }              }         }        printf("%d %I64d\n",cnt,money);    }    return 0;}


0 0