# Untitled

unknown

plain_text

a month ago

2.2 kB

5

Indexable

Never

^{}

The earnings of gold through mining is x units of gold per day. There are n machines available that can be bought and the cost of the ith machine is arr[i] units of gold. It can be decided to buy any machine on any day if there is a sufficient amount of gold to buy that machine and any ith machine can be bought only once. Also, Each machine extracts extra z units of gold per day, i.e. if there are j machines then one can get (x + j * z) units of gold per day. Note that you can buy multiple machines on the same day. Initially, there is no gold. Find the maximum amount of gold that one can get at the end of k days. For example, x = 1, z = 2, n = 3, arr = [3, 2, 4], k = 5 Hence, the answer is 10 and it can be proved that one cannot earn more than 10 units of gold in 5 days. Function Description Complete the function maximumGold in the editor below. The function must return a long integer denoting the maximum amount of gold you can get at the end of k days. maximumGold has the following parameters: x: an integer denoting units of gold you earn per day z: an integer denoting units of gold, machine extract per day arr[arr[0],...arr[n-1]]: An array of integers denoting the costs of all machines k: an integer denoting the number of days Constraints The first line contains an integer, x, that denotes the units of gold you earn per day. The second line contains an integer, z, that denotes the units of gold machine extract per day. The third line contains an integer, n, that denotes the number of machines. Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer that describes arr[i]. The last line contains an integer, k, that denotes the number of days. Sample Input For Custom Testing Sample Output Explanation Here, x = 3, z = 2, n = 3, arr = [4, 2, 3], k = 4 Hence, the answer is 17 and it can be proved that one cannot earn more than 17 units of gold in 4 days. Sample Input For Custom Testing Sample Output Explanation Here, x = 8, z = 3, n = 3, arr = [7, 7, 7], k = 2 Hence, the answer is 16 and it can be proved that one cannot earn more than 16 units of gold in 2 days.

Leave a Comment