/*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. Python网络编程(Sockets)

    一个简单的服务器 #!/usr/bin/python3 # This is server.py file import socket # create a socket object serverso ...

  2. 【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告

    前言 以前做自动化测试的时候一直用的HTMLTestRunner来生成测试报告,后来也尝试过用Python的PyH模块自己构建测试报告,在后来看到了RobotFramework的测试报告,感觉之前用的 ...

  3. idea 设置编译快捷键(代替 ctrl+f9)

    问题描述 今日在设置项目热部署的时候,无奈就是不会自动编译,不知什么原因. 而编译的话,要么去点小按钮 ,要么使用ctrl + f9,实在不便. 且ctrl + f9目测不能更改. 解决办法 借鉴了关 ...

  4. go_install_x_from_github.sh 从 github 安装 go x tools

    bash go_install_x_from_github.sh #!/bin/bash set +e # set -x echo 'GO Utilities: Install golang.org/ ...

  5. 通读cheerio API-网络爬虫

    所谓工欲善其事,必先利其器,所以通读了cheerio的API,顺便翻译了一遍,有些地方因为知道的比较少,不知道什么意思,保留了英文,希望各位不吝告诉我,然后一起把这个翻译完成. ###cheerio ...

  6. IOS-网络(ASI使用)

    ASI与AFN区别 区别: 1.底层实现 1>AFN的底层基于OC的NSURLConnection与NSURLSession 2>ASI的底层基于纯C语言的CFNetWork框架 3> ...

  7. vim中将tab 设置成4个空格

    在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab 对于已保存的文件,可以使用 ...

  8. 基于Open XML 导出数据到Excel

    数据导出的结果: 步骤1.新建一个Excel 文档,模板根据自己需要设置 步骤2.使用OpenXml  打开Excel 文件 步骤3.点击ReflectCode 功能,生成相应的代码文档 using ...

  9. 在jenkins和sonar中集成jacoco(二)--在jenkins中生成jacoco覆盖率报告

    先要在jenkins上安装jacoco的插件,安装完成之后在job的配置项中可以增加这个选项: 第一个录入框是你的覆盖率文件(exec),第二个是class文件目录,第三个是源代码文件目录. 配置好了 ...

  10. Google Web Designer打开白屏问题的解决方案

    Google Web Designer是谷歌出品的一个可视化的  HTML5  网页和广告的设计开发工具  Google Web Designer . 官网地址:https://www.google. ...