https://vjudge.net/contest/393971#overview

http://poj.org/problem?id=2431

A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The truck now leaks one unit of fuel every unit of distance it travels.

To repair the truck, the cows need to drive to the nearest town (no more than 1,000,000 units distant) down a long, winding road. On this road, between the town and the current location of the truck, there are N (1 <= N <= 10,000) fuel stops where the cows can stop to acquire additional fuel (1..100 units at each stop).

The jungle is a dangerous place for humans and is especially dangerous for cows. Therefore, the cows want to make the minimum possible number of stops for fuel on the way to the town. Fortunately, the capacity of the fuel tank on their truck is so large that there is effectively no limit to the amount of fuel it can hold. The truck is currently L units away from the town and has P units of fuel (1 <= P <= 1,000,000).

Determine the minimum number of stops needed to reach the town, or if the cows cannot reach the town at all.

Input

* Line 1: A single integer, N

* Lines 2..N+1: Each line contains two space-separated integers describing a fuel stop: The first integer is the distance from the town to the stop; the second is the amount of fuel available at that stop.

* Line N+2: Two space-separated integers, L and P

Output

* Line 1: A single integer giving the minimum number of fuel stops necessary to reach the town. If it is not possible to reach the town, output -1.

Sample Input

4
4 4
5 2
11 5
15 10
25 10

Sample Output

2

Hint

INPUT DETAILS:

The truck is 25 units away from the town; the truck has 10 units of fuel. Along the road, there are 4 fuel stops at distances 4, 5, 11, and 15 from the town (so these are initially at distances 21, 20, 14, and 10 from the truck). These fuel stops can supply up to 4, 2, 5, and 10 units of fuel, respectively.

OUTPUT DETAILS:

Drive 10 units, stop to acquire 10 more units of fuel, drive 4 more units, stop to acquire 5 more units of fuel, then drive to the town.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; struct node
{
int dis,fuel;
}stop[10005];
bool cmp(node x,node y)
{
return x.dis > y.dis;
}
int main()
{
int n = 0;
int L = 0 , P = 0;
int counter = -1;
cin >> n;
priority_queue<int> Q;
for(int i = 0;i<n;i++)
{
cin >> stop[i].dis >> stop[i].fuel;
}
sort(stop,stop+n,cmp);
cin >> L >> P; Q.push(P);
int p = 0;
while(L > 0 && !Q.empty())
{
int spent = Q.top();
Q.pop();
L -= spent;
while(p < n)
{
if(L <= stop[p].dis)
{
Q.push(stop[p].fuel);
p++;
}
else
{
break;
}
}
counter += 1;
}
if(L <= 0)
{
cout << counter <<endl;
}
else
{
cout << -1 <<endl;
}
return 0;
}

  

A - Expedition的更多相关文章

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

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

  2. POJ 2431 Expedition(探险)

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

  3. poj 2431 Expedition

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12980   Accepted: 3705 Descr ...

  4. POJ 2431 Expedition (STL 优先权队列)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8053   Accepted: 2359 Descri ...

  5. Expedition(优先队列)

    Expedition 点我 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9465   Accepted: 2760 Des ...

  6. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

  7. CF1091F New Year and the Mallard Expedition

    题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: ...

  8. H - Expedition 优先队列 贪心

    来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...

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

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

  10. POJ 2431 Expedition (优先队列+贪心)

    题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...

随机推荐

  1. L2-1、打造稳定可控的 AI 输出 —— Prompt 模板与格式控制

    一.为什么需要 Prompt 模板? 在与 AI 模型交互时,我们经常会遇到输出不稳定.格式混乱的问题.Prompt 模板帮助我们解决这些问题,通过结构化的输入指令来获得可预测且一致的输出结果. 模板 ...

  2. 【2020.11.23提高组模拟】徒(walk) 题解

    [2020.11.23提高组模拟]徒(walk) 题解 题目描述 给一个简单连通无向图,选一个点为起点,每次选一条没有走过的边走,若无则停止.问是否存在一个起点使得无论如何选择,走出来的路径一定是欧拉 ...

  3. Python 潮流周刊#105:Dify突破10万星、2025全栈开发的最佳实践

    本周刊由 Python猫 出品,精心筛选国内外的 400+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...

  4. 探秘Transformer系列之(36)--- 大模型量化方案

    探秘Transformer系列之(36)--- 大模型量化方案 目录 探秘Transformer系列之(36)--- 大模型量化方案 0x00 概述 0x01 8位量化 1.1 LLM.int8() ...

  5. java的随机数Random

    测试1 1 package com.lv.study.pm.second; 2 3 public class TestMath { 4 5 public static void main(String ...

  6. helm常用操作整理

    说明 下面是整理的日常常用的一些helm操作,后面会持续更新 下载chart到本地 helm repo add bitnami https://charts.bitnami.com/bitnami # ...

  7. 解析依赖注入(DI)的本质

    本文由 ChatMoney团队出品 在软件开发中,依赖注入是一种常用的设计模式,它允许我们将类的依赖关系通过构造器或其他方式自动注入.这种模式在控制器架构中尤为常见,它使得类的依赖关系更加灵活和可管理 ...

  8. AI 实战:一键生成数字人视频!

    做自媒体行业的同学都知道,制作一条可发布的视频成本是很高的,通常我们需要先录制原始视频,而录制原始视频的时间通常是发布视频时长的 3-5 倍,之后还需要花费很长的时间剪辑,最终才能制作一条可发布的视频 ...

  9. 袋鼠云数栈 DataOps 数据生产力实践,实现数据流程的自动化和规范化

    袋鼠云产品团队在帮助企业进行数字化转型实践的过程中,发现很多企业在数据生产链路上都有着相同的问题.包括数据团队聚焦于业务需求短期内的快速交付,内部缺少自顶向下的数据生产管理制度,在数据标准.数据生产流 ...

  10. 上线啦丨FlinkX1.12 Beta版正式在Github开源

    万众期待的FlinkX1.12的Beta版今天正式在Github社区开源上线啦!这是FlinkX技术团队潜心打造的新版本的FlinkX,设计文档和使用文档已在社区中推送,大家可以随时下载查阅,喜欢的同 ...