## 17 Apr PMCA Sunday 12:00 Java Homework 20.04.12.

**Question:**

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

**participants.**

*M*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

**, the quality of call**

*i**is 0.*

**i**Help Jack maximize the total quality.

**Input Specification**

The first line will contain 2 integers, ** N,X (1≤N≤105,1≤X≤104)**.

The second line will contain N integers, * M*1,

**2,**

*M***3,…,**

*M***N(1≤**

*M***i≤109).**

*M***Output Specification**

Output the maximum total quality that Jack can achieve through strategically hopping between calls.

**Sample Input 1**

2 2

9 3

**Sample Output 1**

17

**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**

2 3

5 6

**Sample Output 2**

16

**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.

Sorry, the comment form is closed at this time.