Back To School '18: Making Friends

View as PDF

Points: 7 (partial)
Time limit: 0.3s
Java 1.0s
Python 1.0s
Memory limit: 64M
Java 128M
Python 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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.

Subtasks

for all .

Subtask 3 [80%]

No further 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

• commented on March 19, 2019, 8:41 p.m.

My code seems to be failing a test case and I can't figure out why, can someone take a look?

• commented on March 19, 2019, 8:49 p.m.

There cannot be negative participants in a call, so make sure you're not adding negative numbers to your sum.

• commented on March 19, 2019, 10:25 p.m.

Oh I see, thanks!

• commented on Sept. 10, 2018, 9:57 p.m.

Is there any special cases in this problem? The third test case of every batch gives me a WA.

• commented on Sept. 11, 2018, 6:23 a.m.

Your sum may be so the int type overflows.