Minimum Size Of a board

3.1

8 votes
, Basic Programming, Algorithms
Problem

You are given \(n\) pieces and a \(m \times m\) board. The rows and columns are numbered from 1 to \(m\). A cell on the intersection of the \(r_{th}\) row and \(c_{th} \) column is denoted as as \((r, c)\).

The game's goal is to place \(n\) pieces numbered from \(1\) to \(n\) on the board. The \(i_{th}\) piece lies on \((r_i, c_i)\) while the following rule must be satisfied:

For all pairs of pieces \(i\) and \( j\),\(|r_i - r_j| \ge k \ or \ |c_i-c_j|\ge k \). Here, \(|x|\) denotes the absolute value of \(x\).

Determine the smallest size of the board \(m \times m\) on which you can put \(n\) pieces according to the rules.

Input format

The only line contains two integer, \(n ( 1 \le n \le 1000000)\) denoting the number of pieces and \(k(1 \le k \le 1000000)\).

Output format

Print a single integer denoting the minimum value of \(m\) denoting the length of sides of the suitable board.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation
1   2   3
         
4   5    
         
         

 

Editor Image

?