Richard's Gold Experiment

4.5

2 votes
Medium
Problem

Richard has N gold coins. Each coin has a value A[i] associated with it. Richard is too bored after acing his mid-semester examinations. He decides to conduct an experiment that lasts for M days. Each day, Richard can pick any positive number of coins and find the sum of their values. But the value of the chosen coins decreases by K each. Help Richard find the maximum possible cumulative sum at the end of the experiment.

Note : Cumulative sum means the total sum obtained by summing the result he gets each day. Also, the values associated with the coins can become negative during the course of the experiment! The answer can be negative too!

                                             enter image description here

Input format

The first line consists of 3 integers N, M and K respectively.
N integers follow, where the ith integer (A[i]) denotes the initial value associated with the ith coin.

Output format

Print a single integer denoting the answer modulo 109+7. Note that answer modulo 109+7 is always non-negative even if answer is negative.

Constraints

1N105

1K,A[i]1000

1M109

Subtask Points
1M105 20%
Original Constraints 80%
Sample Input
3 3 1
1 2 3
Sample Output
10
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Let the coins having values 1, 2 and 3 be referred as A, B and C respectively.

Day 1 - Richard picks A ,B and C

Values - 0, 1, 2

Sum = 6

Day 2 - Richard picks B and C

Values - 0, 0, 1

Sum = 9

Day 3 - Richard picks C

Values - 0, 0, 0

Sum = 10

Editor Image

?