Description:
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.
For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).
In how many seconds will Mr. Bender get happy?
Input
The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).
Output
In a single line print a single integer — the answer to the problem.
Examples
Input
6 4 3 1
Output
0
Input
9 3 8 10
Output
2
Note
Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure..
在初始某一个位置有一个点这个点每一秒会向四个方向扩散,然后求第几秒的时候可以超过K个
找一个最小符合条件的,我们可以二分枚举答案来做,然后我们怎么求时间为 t 时细胞的总数呢 假设边界是无穷大的
我们先写出前四秒 1 5 13 25 41我们先假设第0秒为1,第一秒就是1+4*1,第二秒就是 5+4*2,第三秒是13+4*3,
第四秒是25+4*4 不难发现规律 a【t】=a【t-1】+4*t,然后求得公式就是2*t*t+2*t+1。
加上边界条件以后就是减去超出边界的
假设到 某一边的距离为 x 超出就为 2 * (t - 1 - x) * (t - 1 - x + 1) / 2 + t - x 这个方向两边都超出了
再然后就是超出的部分有相交的部分 就是角上 假设点到达该角对应两边的距离为 x y 那超出部分为 (t-1-x-y)(t-1-x-y+1)/2
AC代码: