#P5662. [CSP-J 2019] 纪念品

    ID: 6409 远端评测题 1000ms 250MiB 尝试: 2 已通过: 2 难度: 6 上传者: 标签>动态规划 DP2019背包 DPCSP-J 入门级

[CSP-J 2019] 纪念品

Problem Description

Xiaowei suddenly gains a superpower: he knows the prices of NN kinds of souvenirs for each of the next TT 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:

  1. Choose any souvenir; if he has enough coins, buy that souvenir at today’s price.
  2. 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 TT days, Xiaowei’s superpower disappears. Therefore, he will definitely sell all souvenirs on day TT to get coins back.

Xiaowei currently has MM coins. He wants to have as many coins as possible after his superpower disappears.

Input Format

The first line contains three positive integers T,N,MT, N, M, separated by single spaces, representing the number of future days TT, the number of souvenir types NN, and the number of coins Xiaowei currently has MM.

The next TT lines each contain NN positive integers, separated by single spaces. On line ii, the NN integers are Pi,1,Pi,2,,Pi,NP_{i,1}, P_{i,2}, \dots, P_{i,N}, where Pi,jP_{i,j} denotes the price of the jj-th type of souvenir on day ii.

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 100100 coins to buy 55 units of souvenir 11.

On day 3, sell the 55 units of souvenir 11 to get 125125 coins.

On day 4, buy 66 units of souvenir 11, with 55 coins remaining.

On day 6, you must sell all souvenirs to get 300300 coins back; together with the 55 coins left from day 4, this is a total of 305305 coins.

After the superpower disappears, Xiaowei can have at most 305305 coins.

Sample 2 Explanation

The best strategy is:

On day 1, spend all coins to buy 1010 units of souvenir 11.

On day 2, sell all units of souvenir 11 to get 150150 coins, then buy 88 units of souvenir 22 and 11 unit of souvenir 33, with 11 coin remaining.

On day 3, you must sell all souvenirs to get 216216 coins back; together with the 11 coin left from day 2, this is a total of 217217 coins.

After the superpower disappears, Xiaowei can have at most 217217 coins.

Constraints

For 10%10\% of the testdata, T=1T = 1.

For 30%30\% of the testdata, T4T \leq 4, N4N \leq 4, M100M \leq 100, and all prices satisfy 10Pi,j10010 \leq P_{i,j} \leq 100.

For another 15%15\% of the testdata, T100T \leq 100 and N=1N = 1.

For another 15%15\% of the testdata, T=2T = 2 and N100N \leq 100.

For 100%100\% of the testdata, T100T \leq 100, N100N \leq 100, M103M \leq 10^3, and all prices satisfy 1Pi,j1041 \leq P_{i,j} \leq 10^4. The testdata guarantees that at any moment, the number of coins Xiaowei has cannot exceed 10410^4.

Input Format

Output Format

Hint

Translated by ChatGPT 5