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

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230

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 biai 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: nmp (1 <= n <= 100000, 1 <= m <= n, 1 <= p <= 10000), n is
the number of problems available for Aaron,mp 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

题意:

给出Aaron 的初始的做题能力值,然后给出N道题:Aaron 解决这道题至少需要多少能力值a,Aaron 解决了这道题他能增加多少能力值b!

求M天后Aaron 的最大能力值是多少!

PS:

运用优先队列,分别对a和b排序一下!

代码如下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
const double e = exp(1.0);
#define INF 0x3f3f3f3f
//#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
struct node1
{
    int a, b;
    node1() {}
    node1(int _a, int _b): a(_a), b(_b) {}
    bool operator < (const node1 & x) const
    {
        return a > x.a;//最小值优先
    }
};
struct node2
{
    int a, b;
    node2() {}
    node2(int _a, int _b): a(_a), b(_b) {}
    bool operator < (const node2 & x) const
    {
        return b < x.b;//最大值优先
    }
};
int n, m, p;

int main()
{
    int a, b;
    while(~scanf("%d%d%d", &n, &m, &p))
    {
        priority_queue<node1> q1;
        priority_queue<node2> q2;

        for(int i = 0; i < n; i++)
        {
            scanf("%d%d", &a, &b);
            q1.push(node1(a, b));
        }
        int maxx_p = p;
        for(int i = 0; i < m; i++)
        {
            while (!q1.empty())
            {
                int tt_a = q1.top().a;
                int tt_b = q1.top().b;
                if(tt_a <= maxx_p)
                {
                    q2.push(node2(tt_a, tt_b));
                    q1.pop();
                }
                else
                {
                    break;
                }
            }
            if (q2.empty())
            {
                break;
            }
            maxx_p += q2.top().b;
            q2.pop();
        }
        printf("%d\n", maxx_p);
    }
    return 0;
}
/*
3 1 2
1 2
2 3
3 4
3 2 2
1 2
2 3
3 4
*/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-10 02:20:36

ZOJ 3230 Solving the Problems(数学 优先队列啊)的相关文章

ZOJ 2724 Windows 消息队列 (优先队列)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 Message queue is the basic fundamental of windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text cha

HDU 1990 &amp; ZOJ 2992 Monkey Vines(数学啊)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1990 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1991 Problem Description Deep in the Amazon jungle, exceptionally tall trees grow that support a rich biosphere of figs and junipe

zoj 1028 Flip and Shift(数学)

Flip and Shift Time Limit: 2 Seconds      Memory Limit: 65536 KB This puzzle consists of a random sequence of m black disks and n white disks on an oval-shaped track, with a turnstile capable of flipping (i.e., reversing) three consecutive disks. In

ZOJ 3327 Friend Number(数学啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3327 Friend Number Time Limit: 1 Second      Memory Limit: 32768 KB Given a positive integer x, let P(x) denotes the product of all x's digits. Two integers x and y are friend numbers

ZOJ 3600 Taxi Fare(数学啊)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4703 Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou was 10 yuan, plusing 2 yuan per kilometer after the first 3km and 3 yuan per kilometer after

ZOJ 2680 Clock()数学

主题链接:problemId=1680" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1680 There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the small

ZOJ 3488 Conic Section(数学啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4311 The conic sections are the nondegenerate curves generated by the intersections of a plane with one or two nappes of a cone. For a plane perpendicular to the axis of the cone, a circ

zoj 3041 City Selection(数学啊)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2039 The government decided to build some cities in a newly developping area. Now they had N different locations to select from, while there were M factories in this newly developping ar

ZOJ 3778 Talented Chef(数学啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5017 As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of c