Donghyuk's Walk
Time limit2sMemory limit512 MB
With at most 47 blocked cells on an infinite grid, find the largest x coordinate reachable from the origin in exactly K seconds, where waiting is allowed.
Problem
Donghyuk stands at the origin of an infinite two dimensional grid. Some cells of the grid are blocked, and he cannot enter a blocked cell. The origin is not blocked.
Each second Donghyuk may move to one of the four cells next to his current cell (up, right, down, left) that is not blocked. He may also stay where he is.
Given the blocked cells and the time , write a program that finds the largest coordinate of a cell where Donghyuk can be after seconds.
Input
The first line contains the number of blocked cells and the time (, ).
Each of the next lines contains the coordinate and the coordinate of one blocked cell. Both coordinates are integers whose absolute value is at most .
All blocked cells are distinct, and the origin is not among them.
Output
Print the largest coordinate of a cell where Donghyuk can be after seconds.