Sunbathing X57809


Statement
 

pdf   zip

html

One of the most important activities on the beach is sunbathing, trying to get that perfect tan. If Roger does not put on any suncream his skin will burn, but if he puts on too much the suncream will block the rays of the sun. Help Roger optimize the use of his suncream.

At each minute, Roger has the option of putting on more suncream, causing his current sun protection factor (SPF) to equal that of the suncream. If he does not put on any suncream, his SPF decreases by one compared to the previous minute, until it reaches 0. Roger has an ideal sun protection factor I, and the benefit to his skin of one minute of sunbathing is given by the following function, where s is Roger’s current SPF:

f(s)=1000−(sI)2.

Input

An integer 1≤ N≤ 1000 denoting the number of test cases. Each test case consists of four integers M, S, I, Q, where 1≤ M≤ 1000 is the number of minutes that Roger will sunbathe, 1≤ S≤ 50 is the sun protection factor of the suncream, 0≤ IS is Roger’s ideal SPF, and 0≤ Q≤ 20 is the suncream quantity (the number of times that Roger can put on more suncream).

Output

For each test case, a single line with an integer number representing the maximum total benefit that Roger can achieve to his skin.

Observation

In the first example, the maximum benefit is achieved by applying suncream at the first and third minute. In the second example, Roger’s ideal SPF is 0, so he should never put on suncream. In the third example, Roger has no suncream available, so he cannot apply any. In the fourth example, the maximum benefit is achieved by applying suncream at the first minute.

Public test cases
  • Input

    4
    4 10 10 2
    4 10 0 3
    4 10 10 0
    4 10 5 3
    
    

    Output

    3998
    4000
    3600
    3946
    
  • Information
    Author
    Anders Jonsson
    Language
    English
    Official solutions
    Unknown. This problem is being checked.
    User solutions
    C++