[HDU4864]Task (贪心)

时间:2023-03-09 21:34:00
[HDU4864]Task (贪心)

此图和上一篇博客的图一起看有奇效

[HDU4864]Task (贪心)

题意

https://vjudge.net/problem/HDU-4864

思路

贪心

代码

by lyd

我实在是敲不来

#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std; #define LL __int64
const int maxn=1e5+;
struct node{
int x,y;
}e[maxn],f[maxn];
int c[];
int cmp(node a,node b)
{
if(a.x==b.x)return a.y>b.y;
return a.x>b.x;
}
int main()
{
//freopen("C:\\Documents and Settings\\Administrator\\×ÀÃæ\\in.txt","r",stdin);
//freopen("C:\\Documents and Settings\\Administrator\\×ÀÃæ\\out.txt","w",stdout);
//double a = clock();
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j,k,num=;
LL ans=;
for(i=;i<n;i++)
scanf("%d%d",&e[i].x,&e[i].y);
for(i=;i<m;i++)
scanf("%d%d",&f[i].x,&f[i].y);
sort(e,e+n,cmp);
sort(f,f+m,cmp);
memset(c,,sizeof(c));
for(i=,j=;i<m;i++)
{
while(j<n&&e[j].x>=f[i].x)
{
c[e[j].y]++;
j++;
}
for(k=f[i].y;k<=;k++)
{
if(c[k])
{
num++;
c[k]--;
ans=ans+*f[i].x+*f[i].y;
break;
}
}
}
printf("%d %I64d\n",num,ans);
}
//double b = clock();
//printf("%lf\n", (b - a) / CLOCKS_PER_SEC);
return ;
}