No.853 Stones on the Riverbank
タグ : / 解いたユーザー数 7
作問者 :
CuriousFairy315
/ テスター :
Enjapma_kyopro
Problem Statement
It has been discovered that the intended solution is incorrect!!! We are sorry!!!
For the time being, we will make submitted code result in NoOut.For operational reasons, we will leave this as it was when it was set.
The original problem statement follows.
31536000 is playing a game of piling up stones on a riverbank.This riverbank extends infinitely in the horizontal direction, and at every position there is a tower consisting of $0$ levels of stones.
Now, 31536000 has built one tower consisting of $H$ levels of stones right in front of them.
However, a scary demon that tries to knock down stone towers lives on this riverbank.
31536000 noticed that the demon will soon come here, and decided to move the tower.
From now on, 31536000 can perform the following operation.
・Choose one tower consisting of $1$ or more levels of stones, and move one stone to a different tower within a distance of at most the number of levels of stones in the tower. In other words, letting $x$ be the position of the tower and $y$ be its number of levels of stones, choose one tower within $[x-y, x+y]$ and move one stone to that tower.
When performing this operation some number of times to build a tower consisting of $H$ levels of stones at the position a distance $W$ away from here in the positive direction, find the minimum number of operations.
Input
$H$ $W$
・$0 \leq H \leq 10^9$
・$-10^9 \leq W \leq 10^9$
Output
Output the minimum number of operations required.
Print a newline at the end.
Sample
Sample 1
Input
2 1
Output
2
The operations are as follows.
1. Move one stone from the tower at the origin to coordinate $1$.
2. Move one stone from the tower at the origin to coordinate $1$.
Sample 2
Input
3 2
Output
4
The operations are as follows.
1. Move one stone from the tower at the origin to coordinate $2$.
2. Move one stone from the tower at the origin to coordinate $2$.
3. Move one stone from the tower at the origin to coordinate $1$.
4. Move one stone from the tower at coordinate $1$ to coordinate $2$.
Note that at the time of the 3rd operation, the tower at the origin consists of $1$ level, so a stone cannot be placed directly at coordinate $2$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。