#P6022. Happy Water Exchange
Happy Water Exchange
Happy Water Exchange
You are given a promotion in a store. Initially, you have enough money to buy n bottles of "Happy Water". When you drink one bottle, you get 1 bottle cap and m different accessories (one of each type). The store runs an exchange program with two offers:
- You can exchange 5 bottle caps for 1 new bottle.
- For the ith accessory, you can exchange $a_i$ accessories for 1 new bottle. (Here the exchange rate is given in latex as \(a_i\).)
Every time you obtain a new bottle (either bought initially or received via exchange) and drink it, you get additional 1 bottle cap and 1 accessory of each of the m types. Your task is to compute the maximum number of bottles you can drink.
Input constraints: You are given two integers n and m on the first line, followed by a line with m integers \(a_1, a_2, \ldots, a_m\). You may assume that each \(a_i\) is greater than 1.
inputFormat
The first line contains two integers n and m, where n is the number of initially purchased bottles and m is the number of accessory types per bottle.
The second line contains m integers \(a_1, a_2, \ldots, a_m\), where for the ith accessory, you can exchange \(a_i\) accessories for 1 new bottle.
outputFormat
Output a single integer representing the maximum number of bottles of Happy Water you can drink.
sample
5 1
5
7
</p>