Codeforces Round 298 (Div. 2)
B
Covered Path
Codeforces
1400
原题
← AC →
翻译中…

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals $*v*_{1}$ meters per second, and in the end it is $*v*_{2}$ meters per second. We know that this section of the route took exactly $*t*$ seconds to pass.

翻译中…

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by $*d*$ meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed $*d*$ in absolute value), find the maximum possible length of the path section in meters.

翻译中…

Input

翻译中…

The first line contains two integers $*v*_{1}$ and $*v*_{2}$ ($1 ≤ *v*_{1}, *v*_{2} ≤ 100$) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

翻译中…

The second line contains two integers $*t*$ ($2 ≤ *t* ≤ 100$) — the time when the car moves along the segment in seconds, $*d*$ $(0 ≤ *d* ≤ 10)$ — the maximum value of the speed change between adjacent seconds.

翻译中…

It is guaranteed that there is a way to complete the segment so that:

翻译中…
  • the speed in the first second equals $*v*_{1}$,
  • the speed in the last second equals $*v*_{2}$,
  • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed $*d*$.
翻译中…

Output

翻译中…

Print the maximum possible length of the path segment in meters.

翻译中…

Note

翻译中…

In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is $5 + 7 + 8 + 6 = 26$ meters.

翻译中…

In the second sample, as $*d* = 0$, the car covers the whole segment at constant speed $*v* = 10$. In $*t* = 10$ seconds it covers the distance of 100 meters.

翻译中…

样例

Input #1
5 6
4 2
Output #1
26
InputCopy OutputCopy
Input #2
10 10
10 0
Output #2
100
InputCopy OutputCopy
题目信息
题号
534B
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。