The school year is starting soon, so Yunji wants to make some friends through his school's Discord server. In the server, there are calls simultaneously going on, each with participants.
Unfortunately, everyone from Yunji's school dislikes him everyone has important things to do other than Discord, so for every minute he is in the call, person will leave that call forever. However, if he is not in that call, no one will leave the call.
Yunji has 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 Yunji) 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 .
The total quality is the sum of the qualities of every call . If he does not ever join a call , the quality of call is .
Help Yunji maximize the total quality.
Input Specification
The first line will contain integers, .
The second line will contain integers, .
Output Specification
Output the maximum total quality that Yunji can achieve through strategically hopping between calls.
Constraints
Subtask 1 [5%]
for all .
Subtask 2 [15%]
Subtask 3 [80%]
No additional constraints.
Sample Input 1
2 2
9 3
Sample Output 1
17
Explanation for Sample 1
Yunji 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 . The total quality would be .
Sample Input 2
2 3
5 6
Sample Output 2
16
Explanation for Sample 2
Yunji can spend the first minute in call , for a quality of . He can then spend two minutes in call , for a quality of . The total quality is therefore .
Comments
My code seems to be failing a test case and I can't figure out why, can someone take a look?
There cannot be negative participants in a call, so make sure you're not adding negative numbers to your sum.
Oh I see, thanks!
Is there any special cases in this problem? The third test case of every batch gives me a WA.
Your sum may be so the int type overflows.