/*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. CentOS环境Docker安装教程(官方推荐的docker三种方式安装)

    CentOS环境Docker安装教程(官方推荐的docker三种方式安装) 一.使用yum方式安装 1.安装依赖包 $ sudo yum install -y yum-utils device-map ...

  2. http cookie的domain使用

    问题描述 最近遇到了一个因cookie domain设置不正确导致公司自研的分布式session组件无法生效的问题. 公司自研的这套分布式session组件依赖于设置在cookie中的sessionI ...

  3. 第106天:Ajax中同步请求和异步请求

    同步请求和异步请求的区别 1.同步是指:发送方发出数据后,等接收方发回响应以后才发下一个数据包的通讯方式. 用户填写所有信息后,提交给服务器,等待服务器的回应(检验数据),是一次性的.信息错误又要重新 ...

  4. HDU-4035-概率dp-期望-公式化简

    Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  5. 前端构建工具 Grunt 入门

    之前也介绍过前端构建工具 Ant 和 Yeoman,其中 Yeoman 工具就包含了 Grunt 所以就不多说.那么与 Ant 相比 Grunt 有这么几个优点: Javascript 语法,相比 A ...

  6. mysql中limit的用法详解[数据分页常用]

    在我们使用查询语句的时候,经常要返回前几条或者中间某几行的数据,这个时候怎么办呢?不用担心,mysql已经为我们提供了这样一个功能. SELECT * FROM table LIMIT [offset ...

  7. css之grid layout代码解释

    .wrapper { display: grid; grid-template-columns: repeat(3, 1fr);/*grid-template-columns CSS属性定义了网格列的 ...

  8. jQuery的无new创建方法

    一般我们去写一个框架,会采用什么样的设计呢?比如设计一个jQuery框架,一般我们会创建一个函数对象 function jQuery(params){ //构造函数 }jQuery.prototype ...

  9. [转]设置银行卡密码的个人bug

    国庆前去某银行新办了张银行卡,办卡的时候修改了默认的密码.国庆期间要网上购物,结果密码输入3次都错误,所以银行卡被锁定了,只能等国庆后银行上班再去解锁. 国庆结束后跑去银行重置了密码,流程是这样的:1 ...

  10. 2018.11.28 RF基础1

    1 射频元件 高频电阻: 高频电容: 高频电感: 2 传输线 a 传输线效应:阻抗,3M法则. b 同轴线:RF中用 c 微带线: 常用: 1/4变换线 回波损耗:用网络分析仪测量 插入损耗:传输功率 ...