Solar Power

View as PDF

Submit solution

Points: 5
Time limit: 0.1s
Memory limit: 256M

Problem type

Joe, ever-efficient, has now turned to another form of green energy: solar power. Joe owns one solar panel which he will use to produce electricity each day. Each day consists of N minutes, over each of which the Sun changes position from sunrise at position 1 to sunset at position N. The energy collected by the solar panel depends on the distance between its own position and the Sun’s position. Formally, if the solar panel is at a position i and the Sun is at a position j, the energy collected during that minute is N-|i-j|. Joe’s solar panel is an older model, and is rather hard to move. It requires T minutes to move it to a new location, during which time it is still collecting power from its current position. Joe would like to know the maximum total amount of energy he can collect, given that his solar panel may initially be at any position. Note that Joe cannot start moving the solar panel before sunrise.


1 \leq N \leq 10^9

1 \leq T \leq N

Input Format

Input consists of two space-separated integers N and T on a single line.

Output Format

Output on a single line the greatest amount of energy that Joe can collect on a single day.

Sample Input

10 6

Sample Output:

Sun Panel Value
1 4 7
2 4 8
3 4 9
4 4 10
5 4 9
6 4 8
7 8 9
8 8 10
9 8 9
10 8 8


There are no comments at the moment.