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 (500xi+2yi) 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 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.
输出格式:
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.
输入样例:
在这里给出一组输入。例如:
1 2
100 3
100 2
100 1
结尾无空行
输出样例:
在这里给出相应的输出。例如:
1 50004
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct node{
int time;
int rank;
};
bool compt(node &a,node &b){
if(a.time==b.time)return a.rank>b.rank;
return a.time>b.time;
}
int main(){
int m_num,t_num,rk[105]={0};
node m[100001],t[100001];//machine,task
scanf("%d%d",&m_num,&t_num);
// m=(node*)malloc(sizeof(node)*(m_num+1));
// t=(node*)malloc(sizeof(node)*(t_num+1));
for(int i=0;i<m_num;i++)
{
scanf("%d%d",&m[i].time,&m[i].rank);
}
for(int i=0;i<t_num;i++)
{
scanf("%d%d",&t[i].time,&t[i].rank);
}
sort(m,m+m_num,compt);
sort(t,t+t_num,compt);
int temp_j=0,count=0;
long long value=0;
for(int i=0;i<t_num;i++){
while(m[temp_j].time>=t[i].time&&temp_j<m_num){
rk[m[temp_j].rank]++;
temp_j++;
}
for(int j=t[i].rank;j<=100;j++){
if(rk[j]){
count++;
value+=500*t[i].time+2*t[i].rank;
rk[j]--;
break;
}
}
}
cout<<count<<" "<<value<<endl;
system("pause");
}