The Firearms Market
Time limit1sMemory limit1024 MB
Find the largest number of firearms that can be carried from state 1 to state N along a path of total length at most K, where each state on the path caps the carried amount and state 1 and N are uncapped.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Binary search, Greedy
- Solved
- No attempts yet
Problem
The United States consists of states, numbered . Juss's home is in state . There it is customary to judge a man's toughness by how many firearms he owns. Juss wants to be a tough man, so he decided to visit this year's high-tech firearms market held in state .
Luckily for Juss, state has just passed a "patriotic self-defense act", under which the state government pays for every firearm a private person buys at the market. Juss can therefore obtain as many firearms as he wants.
Because of various global crises, however, gasoline is very expensive, and Juss can obtain only units of it for the trip home. The states are connected by two-way highways, and one unit of gasoline covers a distance of km. Two states may be connected by more than one highway.
Moreover, not every state is enthusiastic about seeing millions of firearms on its streets. Different states therefore impose different limits on how many firearms one person may carry. In state a private person may carry at most firearms.
Taking into account both the limited amount of gasoline and the carry limits of the states he passes through, determine the maximum number of firearms Juss can bring home.
Input
The first line contains three integers , , and (, , ): the number of states, the number of highways, and the amount of gasoline bought for the trip home.
The second line contains space-separated integers (), where is the carry limit in state ; if , that state has no limit. You may assume that states and have no limit.
Each of the following lines contains three integers , , and (), meaning that states and are connected by a highway of length km. It is guaranteed that Juss can reach home using units of gasoline.
Output
Print a single integer: the maximum number of firearms Juss can bring home. If he can carry an unlimited number, print instead.