MicrosoftOA #62
Side Largest Square
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & MathBinary Search
There are m tiles of size 1×1 and n tiles of size 2×2. You may choose some of the tiles to form a square on a grid with no overlaps and no gaps. Find the maximum integer side length.
This site uses a standard input/output protocol.
Input
One line m n, 0≤m,n≤10⁹. The original range gives a lower bound of 1, but the source's examples explicitly include 0, so this site also keeps the zero-tile cases.
Output
Output a single integer, the answer.
Example 1
Input:
8 0
Output:
2
Example 2
Input:
4 3
Output:
4
Example 3
Input:
0 18
Output:
8
Example notes
Example 1: 8 unit tiles can only form side length 2, since they are not enough for 9 cells. Example 2: three large tiles plus four small tiles fill a 4×4 square. Example 3: using only large tiles, the largest even side length is 8, which uses 16 tiles and leaves 2.
Editorial
Loading solution…