Expedition
Direct Chinese
Descriptions
A herd of cows grabbed a truck venture into the depths of the jungle expedition. As a relatively poor drivers, unfortunately, he ran a rock and cow managed to pierce tank trucks. It is now running a truck per unit of a unit of fuel leakage.
In order to repair the truck, cows need to travel along a long winding road to the nearest town (distance of not more than 1,000,000 units). In this way, between the current position of the truck and towns, there are N (1 <= N <= 10,000) of the fuel station, cows can stop additional fuel (1..100 units per station).
Human jungle is a dangerous place, especially dangerous for cows. Therefore, the cows want as little as possible fuel stop on the way to town. Fortunately, the fuel tank capacity of their trucks is very large, it can accommodate the amount of fuel actually no limit. L truck units present from the town, a P-fuel units (1 <= P <= 1,000,000 ).
The minimum stay is determined to reach the desired number of towns, or cows can not reach the town.
In order to repair the truck, cows need to travel along a long winding road to the nearest town (distance of not more than 1,000,000 units). In this way, between the current position of the truck and towns, there are N (1 <= N <= 10,000) of the fuel station, cows can stop additional fuel (1..100 units per station).
Human jungle is a dangerous place, especially dangerous for cows. Therefore, the cows want as little as possible fuel stop on the way to town. Fortunately, the fuel tank capacity of their trucks is very large, it can accommodate the amount of fuel actually no limit. L truck units present from the town, a P-fuel units (1 <= P <= 1,000,000 ).
The minimum stay is determined to reach the desired number of towns, or cows can not reach the town.
Input
* Line 1: a single integer, N
* row 2..N + 1: Each line contains two integers separated by a space, is used to describe the fuel stops: a first integer is the distance from the town to the stop point; a second one is the amount of fuel available to the site.
* Line N + 2: two integers separated by a space, L and P.
* row 2..N + 1: Each line contains two integers separated by a space, is used to describe the fuel stops: a first integer is the distance from the town to the stop point; a second one is the amount of fuel available to the site.
* Line N + 2: two integers separated by a space, L and P.
Output
* Line 1: A single integer giving fuel to reach the minimum required number of cities and towns to stay. If you can not reach the town, then output -1.
Sample Input
4 4 4 5 2 11 5 15 10 25 10
Sample Output
22
Hint
Enter the details:
a truck from the town's 25 units; this truck has 10 fuel units. Along this road, the distance from the town 4,5,11 and 15 has four fuel stations (the distance from the initial distance of truck 21,20,14 and 10). These stop means may be respectively the fuel up to 4, 2, 5 and 10 the fuel units.
Output details:
Driver 10 units, stopped to buy 10 units of fuel, to open four units, to stop fuel purchase 5 units, then drove to the town.
a truck from the town's 25 units; this truck has 10 fuel units. Along this road, the distance from the town 4,5,11 and 15 has four fuel stations (the distance from the initial distance of truck 21,20,14 and 10). These stop means may be respectively the fuel up to 4, 2, 5 and 10 the fuel units.
Output details:
Driver 10 units, stopped to buy 10 units of fuel, to open four units, to stop fuel purchase 5 units, then drove to the town.
Topic Link
If I passed a gas station, I'll get right to the oil plus the station, then I can always go, until you come out of oil, this time in front of me out of oil which can add up to that plus continue to walk, talk these stations can be placed in the priority queue
AC Code
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <sstream> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define Mod 1000000007 #define eps 1e-6 #defineLong Long LL #define INF 0x3f3f3f3f #define MEM (X, Y) Memset (X, Y, the sizeof (X)) #define MAXN. 5 100000 + the using namespace STD; struct Node { int DIS; // from int value; // oil BOOL operator <( const Node C &) const // according to descending order from { return DIS> c.dis; } }; Node A [MAXN]; The priority_queue < int > Q; int L, P, N; int main() { cin>>N; for(int i=0;i<N;i++) cin>>a[i].dis>>a[i].value; cin>>L>>P; sort(a,a+N);//排序 q.push(P); int ans=0,i=0; while(L>0&&!q.empty()) { ans++;//用了几个加油站 L-=q.top(); q.pop(); while(i<N&&L<=a[i].dis)// L <= A [I] .dis, i.e. through the feed stations, en-queuing { q.push (A [I] .Value); I ++ ; } } IF (L> 0 ) COUT << - . 1 << endl; the else COUT << ans- . 1 << endl; // first oil own return 0 ; }