HDU 4864 Task (multiset)

HDU 4864

Task

Task

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2221 Accepted Submission(s): 572

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

2014 Multi-University Training Contest 1

直接使用multiset进行贪心。 按照y从大到小排序。 然后每次选择y尽量大,x尽量大的。

/* ***
Author :kuangbin
Created Time :2014/7/23 21:43:15
File Name :E:\2014ACM\比赛\2014多校训练\2014多校1\HDU4864.cpp
************************************************ */

#include <stdio.h>

#include <string.h>

#include

#include

#include

#include

#include

#include

#include

#include <math.h>

#include <stdlib.h>

#include <time.h>
using namespace std;
struct Node
{
int x,y;
void input()
{
scanf(“%d%d”,&x,&y);
}
Node(int _x = 0,int _y = 0)
{
x = _x;
y = _y;
}
};
struct classcomp
{
bool operator()(const Node &a,const Node &b)const
{
if(a.x != b.x)return a.x > b.x;
else return a.y> b.y;
}
};
multiset<Node,classcomp>mt;
multiset<Node,classcomp>::iterator it;

const int MAXN = 100010;
Node node1[MAXN];
Node node2[MAXN];
bool cmp(Node a,Node b)
{
return a.y < b.y;
}

int main()
{
//freopen(“in.txt”,”r”,stdin);
//freopen(“out.txt”,”w”,stdout);
int n,m;
while(scanf(“%d%d”,&n,&m) == 2)
{
for(int i = 0;i < n;i++)node1[i].input();
for(int i = 0;i < m;i++)node2[i].input();
mt.clear();
sort(node1,node1+n,cmp);
sort(node2,node2+m,cmp);
int id = 0;
int ans1 = 0;
long long ans2 = 0;
for(int i = 0;i < n;i++)
{
while(id < m && node2[id].y <= node1[i].y)
{
mt.insert(node2[id]);
id++;
}
it = mt.lower_bound(Node(node1[i].x,1000));
if(it != mt.end())
{
ans1++;
ans2 += (long long)500(\it).x + 2*(*it).y;
mt.erase(it);
}
}
printf(“%d %I64d\n”,ans1,ans2);
}
return 0;
}

------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 293.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%