#P3778. [APIO2017] 商旅
[APIO2017] 商旅
Description
After a long trek across the vast Australian outback, you arrive alone in Cobar with a backpack. Captivated by the city’s prosperous and beautiful markets, you decide to settle down and become a merchant. Cobar has markets, numbered from to , connected by directed roads. Traversing each road takes some amount of time.
There are different types of goods in Cobar, numbered from to . Each market has its own prices for each good, and the buy and sell prices may differ. Not every market buys and sells every good: a market may support both buying and selling only for a subset of goods; for a particular good, a market may only buy but not sell, or only sell but not buy. If a market buys a certain good, the quantity it buys is unlimited; similarly, if a market sells a certain good, the quantity it sells is unlimited.
To gain profit more quickly, you decide to find the cycle with the highest profit efficiency. A cycle means starting from some market with an empty backpack, traveling along roads through several markets, and finally returning to the starting point. It is allowed to pass through the same market or the same road multiple times within the cycle. When passing a market, you may buy or sell goods. Once you buy a good, you must carry it in your backpack. Because your backpack is very small, you can hold at most one good at any time. When buying a good, you do not need to consider whether you have enough money; when selling, note that you can only sell the good you currently hold.
The profit gained from a cycle is the total money obtained from selling minus the total money spent on buying during the cycle. The time spent on a cycle is the sum of the traversal times of all roads along the cycle. The profit efficiency of a cycle is the profit divided by the time spent. Note that the profit efficiency of a cycle with no transactions is .
You need to find, among all cycles with strictly positive total time, the maximum profit efficiency. Output the value floored to an integer. If no cycle can yield a positive profit, output .
Input Format
The first line contains positive integers , , and , denoting the number of markets, the number of roads, and the number of goods, respectively.
The next lines describe the markets. In line , there are integers $B_{i,1}, S_{i,1}, B_{i,2}, S_{i,2}, \cdots, B_{i,K}, S_{i,K}$. For any , the integers and denote the buying and selling price at market for good , respectively. If a transaction price is , then that transaction is not available for that good at that market.
Then follow lines. In line , there are integers , indicating there is a directed road from market to market with travel time minutes.
Output Format
Output a single integer: the maximum profit efficiency over all cycles, floored to an integer. If no cycle can be profitable, output .
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
2
Hint
Sample explanation.
In the sample, consider the two cycles 1−2−3−1 and 1−4−3−1.
Consider the cycle 1−2−3−1: the total time is minutes. The best sequence of transactions is: at market , buy good (spending ); at market , sell good (gaining ), then immediately buy good (spending ); pass through market carrying good , and upon returning to market , sell it (gaining ). The total profit is . The profit efficiency is , whose floor is .
Consider the cycle 1−4−3−1: the total time is minutes. The best sequence of transactions is: at market , buy good (spending ); at market , sell good (gaining ); then pass through market and return to market . The total profit is . The profit efficiency is , whose floor is .
Therefore, the maximum profit efficiency over all cycles is .
Subtasks.
Across all testdata, the following hold: , , . If in market for good both buying and selling are available, then . For road (), it is guaranteed that and . There do not exist indices with such that .
| Subtask | Score | Additional conditions | Explanation |
|---|---|---|---|
| You can only buy goods at market . | |||
| All roads take minute to traverse. | |||
| At each market, the buy and sell prices are the same (prices may differ across markets). | |||
| None | None. |
Translated by ChatGPT 5
京公网安备 11011102002149号