• محدودیت زمان: ۲ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Again, Neverland has experienced a very bad economic condition over the past few months. The value of Oshloob, the national currency of Neverland, changes against one unit of gold very rapidly. People in Neverland, all wondering about their savings, are trying to exchange their savings with gold coins.

Dr. Predictman who is a data scientist, has obtained a prediction of the price (in Oshloobs) of a gold coin for the next nn days based on the existing data over the past 40 years. He believes his prediction, and now he want to increase his savings based on it. He was wondering how much savings he has at the end of the nn-th day assuming that he has cc Oshloobs at the beginning of the first day. Since Dr. Predictman is not a programmer, he asks you to help to find his answer.

ورودی

The first line of the input contains two integers cc (0c30000 \leq c \leq 3000), Dr. Predictman’s initial savings in Oshloobs, and nn (0n300 \leq n \leq 30), the period of his prediction. Each of the next following nn lines contains an integer pip_i (1000pi20001000 \leq p_i \leq 2000) denoting the price of a gold coin at day ii (1in1 \leq i \leq n) in Oshloobs.

خروجی

The output contains just an integer, which indicates the maximum savings he can obtain at the end of the nn-th day assuming that Dr. Predictman exchanges all his remaining gold coins (if there is any) to Oshloobs at the end of the nn-th day.

مثال

ورودی نمونه ۱

1000 3
1000
1100
1200
Plain text

خروجی نمونه ۱

1200
Plain text

ورودی نمونه ۲

2000 4
1000
2000
1500
1800
Plain text

خروجی نمونه ۲

4600
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.