QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#22385. Stock Market

統計

Despite their innate prudence, the cows took a beating in the home mortgage market and now are trying their hand at stocks. Happily, Bessie is prescient and knows not only today's $S$ $(2 \le S \le 50)$ stock prices but also the future stock prices for a total of $D$ days $(2 \le D \le 10)$.

Given the matrix of current and future stock prices on various days $(1 \le PR_{sd} \le 1,000)$ and an initial $M$ $(1 \le M \le 200,000)$ units of money, determine an optimal buying and selling strategy in order to maximize the gain realized by selling stock on the final day. Shares must be purchased in integer multiples, and you need not spend all the money (or any money). It is guaranteed that you will not be able to earn a profit of more than 500,000 units of money.

Consider the example below of a bull (i.e., improving) market, the kind Bessie likes most. In this case, $S=2$ stocks and $D=3$ days. The cows have 10 units of money to invest.

                   Today's price
                   |   Tomorrow's price
                   |   |  Two days hence
             Stock |   |  | 
              1    10 15 15
              2    13 11 20

If money is to be made, the cows must purchase stock 1 on day 1. Selling stock 1 on day 2 and quickly buying stock 2 yields 4 money in the bank and one share of 2. Selling stock 2 on the final day brings in 20 money for a total of 24 money when the 20 is added to the bank.

Input

  • Line 1: Three space-separated integers: $S$, $D$, and $M$
  • Lines $2,\ldots,S+1$: Line $s+1$ contains the $D$ prices for stock $s$ on days $1,\ldots,D$: $PR_{sd}$

Output

  • Line 1: The maximum amount of money possible to have after selling on day $D$.

Examples

Input 1

2 3 10
10 15 15
13 11 20

Output 1

24

Problem credits: Rob Kolstad(?), 2008

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.