|
TaskTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1736 Accepted Submission(s): 437
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
Sample Output
|
机器任务从大到小排序,贪心的思想,考虑水平最高的任务能否被完成,可以就用时间最短的机器去完成他。
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <string>
#include <queue>
using namespace std;
#define LL long long
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define mset(a) memset(a,0,sizeof a)
#define FR(a) freopen(a,"r",stdin)
#define FW(a) freopen(a,"w",stdout)
#define PI 3.141592654
const LL MOD = 1000000007;
const int maxn=100011;
const double eps=1e-9;
struct task
{
int x,y;
};
map <int,int> mapp;
task a[maxn],b[maxn];
bool cmp(task a,task b)
{
if(a.x==b.x) return a.y>b.y;
return a.x>b.x;
}
int n,m;
int main()
{
while (cin>>n>>m)
{
mapp.clear();
REP(i,0,n-1)
scanf("%d%d",&a[i].x,&a[i].y);
REP(i,0,m-1)
scanf("%d%d",&b[i].x,&b[i].y);
sort(a,a+n,cmp);
sort(b,b+m,cmp);
int mac=0;
int ans1=0;
LL ans2=0;
REP(ta,0,m-1)
{
while(mac<n && a[mac].x>=b[ta].x) {
mapp[a[mac].y]++;
mac++;
}
map<int,int>::iterator it=mapp.lower_bound(b[ta].y);
if(it==mapp.end()) continue;
ans1++;
int t=it->first;
mapp[t]--;
if(mapp[t]==0) mapp.erase(it);
ans2+=500*b[ta].x+2*b[ta].y;
}
printf("%d %I64d\n",ans1,ans2);
}
}