/*ZOJ Problem Set - 3230Solving the Problems

--------------------------------------------------------------------------------

Time Limit: 2 Seconds      Memory Limit: 32768 KB

--------------------------------------------------------------------------------

Programming is fun, Aaron is addicted to it. In order to improve his programming skill, he decides to solve one programming problem per day. As you know, different problems have different properties, some problems are so difficult that there are few people can solve it, while some problems are so easy that almost everyone is able to tackle it.

Programming skill can be measured by an integer p. And all problems are described by two integers ai and bi. ai indicates that if and only if P >= ai, you can solve this problem. bi indicates that after you solve this problem, your programming skill can be increased by bi.

Given the initial programming skill p of Aaron, and the information of each problem, Aaron want to know the maximal programming skill he can reach after m days, can you help him?

Input

Input consists of multiple test cases (less than 40 cases)!

For each test case, the first line contains three numbers: n, m, p (1 <= n <= 100000, 1 <= m <= n, 1 <= p <= 10000), n is the number of problems available for Aaron, m, p as mentioned above.

The following n lines each contain two numbers: ai and bi (1 <= ai <= 10000, 1 <= bi <= 10000) describe the information of the i-th problem as memtioned above.

There's a blank line between consecutive cases.

Output

For each case, output the maximal programming skill Aaron can reach after m days in a line.

Sample Input

2 2 1
1 2
7 3 3 1 2
1 2
2 3
3 4 Sample Output 3
5 --------------------------------------------------------------------------------
Author: ZHOU, Yilun
Source: ZOJ Monthly, July 2009
题意:
我基本可以理解,你也可以的。
解法:
开始我对bi从大到小排序,超时,也对每次都从头开始循环,超时才怪。
看了别人的思路才发现该用ai从小到大排序。每次找优先队列的最大值
,即q.top()。
*/
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 260000
struct PB
{
int ai;
int bi;
bool operator < (const PB& a)const
{
return ai<a.ai;
}
} pb[maxn];
int i,n,m,p;
int main()
{ while(~scanf("%d%d%d",&n,&m,&p))
{
priority_queue<int> q;//再循环内定义
for(i=; i<n; i++)
scanf("%d%d",&pb[i].ai,&pb[i].bi);
sort(pb,pb+n);
i=;
while(pb[i].ai<=p&&i<n)
{
q.push(pb[i].bi);
i++;
}
while(m--)
{
if(!q.empty())
{
p+=q.top();
q.pop();
while(pb[i].ai<=p&&i<n)
{
q.push(pb[i].bi);
i++;
}
}
else
{
break;
} }
printf("%d\n",p);
}
return ;
}

ZOJ-3230-Solving the Problems的更多相关文章

  1. ZOJ 3230 Solving the Problems(数学 优先队列啊)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is ...

  2. TED #09# You don't have to be an expert to solve big problems

    Tapiwa Chiwewe: You don't have to be an expert to solve big problems Collection noticed a haze hangi ...

  3. Elixir - Hey, two great tastes that go great together!

    这是Elixir的作者 José Valim 参与的一次技术访谈,很有料,我们可以了解Elixir的一些设计初衷,目标等等. 原文在: http://rubyrogues.com/114-rr-eli ...

  4. (转)A Survival Guide to a PhD

    Andrej Karpathy blog About Hacker's guide to Neural Networks A Survival Guide to a PhD Sep 7, 2016 T ...

  5. hdu 5057 Argestes and Sequence(分块算法)

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))

    传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...

  7. How to (seriously) read a scientific paper

    How to (seriously) read a scientific paper Adam Ruben’s tongue-in-cheek column about the common diff ...

  8. July 3rd, Week 28th Sunday, 2016

    2016-07-03 First-hand experience is often necessary for personal growth. 亲身体验通常是成长所必须的. Although som ...

  9. hdu5057 Argestes and Sequence 分块

    Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submiss ...

  10. Codeforces 528D Fuzzy Search(FFT)

    题目 Source http://codeforces.com/problemset/problem/528/D Description Leonid works for a small and pr ...

随机推荐

  1. Lua中获取table长度

    -- table.getn(tableName) 得到一个table的大小,等同于操作符# -- 要注意的是:该table的key必须是有序的,索引是从1开始的. --例如有序的 local xian ...

  2. MAC终端安装grunt--javascript世界得构建工具

    祝贺我成为前端啦!~~从年前得小测试到今年得前端,成功转型!我真是一个进步得好青年,好少女! 这两天出去受虐,面了两家前端,表现非常不好,还是回到我现在得公司好好沉淀技术,做前端,要经常性得整理总结, ...

  3. linux 环境下 eas console的运行

    1)访问 http://<HOST>:19000/easconsole/ 2)然后下载 jnlp 文件. 3)找个jre, 用javaws 运行 jnlp文件

  4. 雷林鹏分享:Ruby 日期 & 时间(Date & Time)

    Ruby 日期 & 时间(Date & Time) Time 类在 Ruby 中用于表示日期和时间.它是基于操作系统提供的系统日期和时间之上.该类可能无法表示 1970 年之前或者 2 ...

  5. 拖拉记录上下移动--Ajax UI

    所谓的 Ajax 拖拉 UI,就是直接用鼠标进行拖拉排序,这种方式对用户来说操作速度更快. 拖拉的 UI 需要额外的前端套件,这里介绍 jQuery UI 的 Sortable Plugin,并直接使 ...

  6. 转-Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)

    http://blog.chinaunix.net/space.php?uid=10167808&do=blog&id=26042   1)BIOS自检2)启动Grub/Lilo3)加 ...

  7. 【hive】时间段为五分钟的统计

    问题内容 今天遇到了一个需求,需求就是时间段为5分钟的统计.有数据的时间戳.对成交单量进行统计. 想法思路 因为数据有时间戳,可以通过from_unixtime()来获取具体的时间. 有了具体的时间, ...

  8. 建造者模式 build

    引出建造者模式: package com.disign.build; /** * Created by zhen on 2017-05-19. */ public class BuildPersonT ...

  9. FIS 的思想和优点

    资源表 各种性能优化算法的加载框架 依赖声明有助于组件化 资源自动合并 链接 与webpack对比

  10. HDU3488Tour (KM算法)

    题意:   有N个点,M个单向边,现在要你设计N条路线覆盖所有的点,每个点都属于且值属于一个环.(为什么是N条边:和最小生成树为什么有N-1条边是一样的证明). 解析:  每个点都有一个喜欢对象(出度 ...