Charged Courier
View as PDFA courier must travel through a network of cities from city to city
. Each road can only be
used in its listed direction, gives a certain delivery reward, and consumes some amount of battery.
The courier starts with at most battery units and cannot spend more than
battery units over
the whole trip. Determine the maximum total reward the courier can collect while reaching city
.
If it is impossible to reach city
, output
-1.
Input
The first line contains three integers ,
, and
: the number of cities, the number of roads,
and the maximum battery that may be spent.
Each of the next lines contains four integers
,
,
, and
, describing a
directed road from city
to city
with reward
and battery cost
.
Output
Output one integer: the maximum reward possible while reaching city using at most
battery
units, or
-1 if city cannot be reached.
Constraints
Example 1
Input
4 5 7
1 2 10 3
2 4 20 4
1 3 25 5
3 4 10 3
2 3 15 2
Output
30
Explanation
The courier can travel from city to city
to city
, spending
battery and
collecting
reward. The route through city
from city
would collect more
reward, but it spends too much battery.
Example 2
Input
3 2 4
1 2 100 5
2 3 100 1
Output
-1
Comments