【解题报告】 Task

【解题报告】 Task

题目:任务

解题思路:

贪心

我们可以贪心每个任务的等级,再贪心每个任务的时间,我们这样排一下序,再循环一下,就可以得到正确的答案了

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const long long maxn=100010;
long long n,m;
struct task
{
    long long x;
    long long y;
}; 
task f[maxn];
task e[maxn];
long long cnt[105],ans,num;
long long cmp(task a,task b)
{
    if(a.x==b.x)
    return a.y>b.y;
    return a.x>b.x;
}
int main()
{
    cin>>n>>m;
    for(long long i=1;i<=n;i++)
    cin>>e[i].x>>e[i].y;
    for(long long i=1;i<=m;i++)
    cin>>f[i].x>>f[i].y;
    sort(e+1,e+1+n,cmp);
    sort(f+1,f+1+m,cmp);
    long long j=1;
    for(long long i=1;i<=m;i++)
    {
        while(j<=n&&e[j].x>=f[i].x)
        {
            cnt[e[j].y]++;
            j++;
        }
        for(long long k=f[i].y;k<=100;k++)
        {
            if(cnt[k])
            {
                num++;
                cnt[k]--;
                ans+=500*f[i].x+2*f[i].y;
                break;
            }
        }
    }
    cout<<num<<" "<<ans<<endl;
    return 0; 
}

PS:实在不懂为什么别人的代码要用pair

猜你喜欢

转载自www.cnblogs.com/wweiyi2004/p/11371060.html