首先我们可以发现如果错过了一个加油站,而继续往前走的时候没有油了,可以再假装之前经过加油站的时候加过油

于是我们维护一个大根堆,表示错过的加油站是哪些,每当没有油的时候从堆顶取出最大值加上去即可

 /**************************************************************
Problem: 1747
User: rausen
Language: C++
Result: Accepted
Time:20 ms
Memory:916 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <queue> using namespace std;
const int N = 1e4 + ; inline int read(); struct data {
int w, add; inline void get() {
w = read(), add = read();
} inline bool operator < (const data &d) const {
return w > d.w;
}
} a[N]; int n, tot, ans;
priority_queue <int> h; int main() {
int i;
n = read();
for (i = ; i <= n; ++i) a[i].get();
a[].w = read(), tot = read();
sort(a + , a + n + );
a[n + ].w = ;
for (i = ; i <= n + ; ++i) {
tot -= (a[i - ].w - a[i].w);
while (tot < && !h.empty()) {
++ans;
tot += h.top(), h.pop();
}
if (tot < ) {
puts("-1");
return ;
}
h.push(a[i].add);
}
printf("%d\n", ans);
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}

BZOJ1747 [Usaco2005 open]Expedition 探险的更多相关文章

  1. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  4. Planning The Expedition(暴力枚举+map迭代器)

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  5. 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划

    [BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...

  6. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  7. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  8. POJ 2431 Expedition(优先队列、贪心)

    题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...

  9. ASP.NET 5探险(3):使用UMEditor并实现图片上传

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:今天将继续上一篇来讲解百度富文本Web编辑器UEditor或UMEditor的使用. ...

随机推荐

  1. Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 思路

    C. Guess Your Way Out! time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. T-SQL Apply的用法

    SQL Server 2005 新增 cross apply 和 outer apply 联接语句,增加这两个东东有啥作用呢? 我们知道有个 SQL Server 2000 中有个 cross joi ...

  3. 数据库mysql中distinct关键词

    在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 例如,在学生信息表中,你想查询该学校有多少个系.例如, ...

  4. [转载] HTTP请求的TCP瓶颈分析

    原文: http://bhsc881114.github.io/2015/06/23/HTTP%E8%AF%B7%E6%B1%82%E7%9A%84TCP%E7%93%B6%E9%A2%88%E5%8 ...

  5. Service 与 Thread 的区别

    很多时候,你可能会问,为什么要用 Service,而不用 Thread 呢,因为用 Thread 是很方便的,比起 Service 也方便多了,下面我详细的来解释一下. 1). Thread:Thre ...

  6. spring相关资源

    1. 文档中英文 Spring Framework Reference Documentation http://docs.spring.io/spring/docs/4.1.7.RELEASE/sp ...

  7. Spring MVC 之类型转换(五)

    虽然SpringMVC可以自动绑定多种数据类型,但是有时候有些特殊的数据类型还是会在绑定时发生错误,需要我们自己书写类型转换完成绑定. SpringMVC中提供两种绑定方式:以时间转换为例. 1.属性 ...

  8. ListView数据显示混乱

    在使用自定义ListView视图时,经常会采用重用ListView中视图的方式来提高滑动和显示效率,但是随之而来的一个问题是listview中数据经常显示混乱. 通常情况下,我们重写的方法是这样的: ...

  9. on delete cascade 和on update cascade

    这是数据库外键定义的一个可选项,用来设置当主键表中的被参考列的数据发生变化时,外键表中响应字段的变换规则的.update 则是主键表中被参考字段的值更新,delete是指在主键表中删除一条记录:on ...

  10. Java的动态绑定

    看这段代码 Father father = new Son(); 父类引用指向子类对象,这是java的多态特性,有多态引到动态绑定,如何引入呢,看这个代码: class Father{ private ...