14 Apr PMCA Friday 19:00 Python Homework 20.04.10.
The school year is starting soon, so Jack wants to make some friends through his school’s Discord server. In the server, there are N calls simultaneously going on, each with M participants.
Unfortunately, everyone has important things to do other than Discord, so for every minute he is in the ith call, 1 person will leave that call forever. However, if he is not in that call, no one will leave the call.
Jack has X minutes before school starts. At the beginning of each minute, he can either leave the current call and join a different call, or stay in the current call. The quality of each call is defined as the sum of the number of participants (excluding Jack) for every minute he stays in that call. Note that there can’t be negative participants in the call, so the sum is capped at 0.
The total quality is the sum of the qualities of every call i (1≤i≤N). If he does not ever join a call i, the quality of call i is 0.
Help Jack maximize the total quality.
The first line will contain 2 integers, N,X (1≤N≤105,1≤X≤104).
The second line will contain N integers, M1,M2,M3,…,MN(1≤Mi≤109).
Output the maximum total quality that Jack can achieve through strategically hopping between calls.
Sample Input 1
Sample Output 1
Explanation for Sample 1
Jack can spend all his time in the first call: if he does there will be 9 participants in the call in the first minute, and 8 participants in the second minute. The quality of this call would be 9+8=17. The total quality would be 17+0=17.
Sample Input 2
Sample Output 2
Explanation for Sample 2
Jack can spend the first minute in call 1, for a quality of 5. He can then spend two minutes in call 2, for a quality of 6+5=11. The total quality is therefore 5+11=16.