51nod dai1163 最高的奖励

题目链接:

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163

题解:

先按时间升序排列,再把价值降序排列,一直更新最小值就行了。(自己用的优先队列更的新)

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define  inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 50000+10;

struct node
{
    int time;
    int val;
}s[maxn];

int cmp(node a,node b)
{
    if(a.time!=b.time)
        return a.time<b.time;
    return a.val>b.val;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&s[i].time,&s[i].val);
        sort(s,s+n,cmp);
        priority_queue<int,vector<int>,greater<int> >q;
        while(!q.empty())
            q.pop();
        int len=1;
        int pos=s[0].time;
        q.push(s[0].val);
        for(int i=1;i<n;i++)
        {
            if(s[i-1].time!=s[i].time)
            {
                q.push(s[i].val);
                pos=s[i].time;
                len++;
            }
            else if(s[i-1].time==s[i].time)
            {
                if(len<pos&&len<s[i].time)
                {
                    q.push(s[i].val);
                    len++;
                }
                else
                {
                    int num=q.top();
                    if(num<s[i].val)
                    {
                        q.pop();
                        q.push(s[i].val);
                    }
                }
            }
        }
        ll sum=0;
        while(!q.empty())
        {
            int num=q.top();
            //printf("%d\n",num);
            sum+=num;
            q.pop();
        }
        printf("%lld\n",sum);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值