#P2648. 赚钱
赚钱
Description
zzy now decides to travel around China and make some money along the way. In any single visit to a city, zzy can earn at most yuan. After that, he may choose to retire (i.e., stop earning) or go to other cities to work. Of course, he can work elsewhere for a while and then return to the original city to earn another yuan. The number of such round trips is unlimited.
There are directed paths between cities, and there are cities in total, numbered from to . Path goes from city to city , and traveling along these paths costs nothing.
zzy can also take a flight from one city to another. There are directed flights; the -th flight goes from city to city with a cost of yuan. If zzy has no cash on hand, he can pay the airfare with money he will earn in the future.
zzy may start earning from any city and may retire at any time and in any city. Now zzy wants to know: if there is no limit on working time, how much money can he earn in total? If the amount he can earn has no limit, output orz.
Input Format
The first line contains space-separated positive integers .
Lines to each contain space-separated integers , describing a directed path from city to city .
The next lines each contain space-separated positive integers , describing a directed flight from city to city with a cost of .
Output Format
If the amount zzy can earn is unbounded, output orz. Otherwise, output the maximum amount of money zzy can earn under the given rules.
100 3 5 2
1 5
2 3
1 4
5 2 150
2 5 120
250
Hint
For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号