#P5662. [CSP-J 2019] 纪念品
[CSP-J 2019] 纪念品
Problem Description
Xiaowei suddenly gains a superpower: he knows the prices of kinds of souvenirs for each of the next days. The price of a souvenir means the number of coins needed to buy one unit of that souvenir, and also the number of coins you get back by selling one unit of that souvenir.
Each day, Xiaowei can perform the following two types of transactions an unlimited number of times:
- Choose any souvenir; if he has enough coins, buy that souvenir at today’s price.
- Sell any souvenir he is holding, and exchange it for coins at today’s price.
The coins obtained from selling souvenirs can be used immediately to buy souvenirs. Souvenirs bought on the same day can also be sold on the same day for coins. Of course, he may also keep holding souvenirs.
After days, Xiaowei’s superpower disappears. Therefore, he will definitely sell all souvenirs on day to get coins back.
Xiaowei currently has coins. He wants to have as many coins as possible after his superpower disappears.
Input Format
The first line contains three positive integers , separated by single spaces, representing the number of future days , the number of souvenir types , and the number of coins Xiaowei currently has .
The next lines each contain positive integers, separated by single spaces. On line , the integers are , where denotes the price of the -th type of souvenir on day .
Output Format
Output only one line containing one positive integer, representing the maximum number of coins Xiaowei can have after his superpower disappears.
6 1 100
50
20
25
20
25
50
305
3 3 100
10 20 15
15 17 13
15 25 16
217
Hint
Sample 1 Explanation
The best strategy is:
On day 2, spend all coins to buy units of souvenir .
On day 3, sell the units of souvenir to get coins.
On day 4, buy units of souvenir , with coins remaining.
On day 6, you must sell all souvenirs to get coins back; together with the coins left from day 4, this is a total of coins.
After the superpower disappears, Xiaowei can have at most coins.
Sample 2 Explanation
The best strategy is:
On day 1, spend all coins to buy units of souvenir .
On day 2, sell all units of souvenir to get coins, then buy units of souvenir and unit of souvenir , with coin remaining.
On day 3, you must sell all souvenirs to get coins back; together with the coin left from day 2, this is a total of coins.
After the superpower disappears, Xiaowei can have at most coins.
Constraints
For of the testdata, .
For of the testdata, , , , and all prices satisfy .
For another of the testdata, and .
For another of the testdata, and .
For of the testdata, , , , and all prices satisfy . The testdata guarantees that at any moment, the number of coins Xiaowei has cannot exceed .
Input Format
Output Format
Hint
Translated by ChatGPT 5