CCCGuide

Problem J5: Square Pool

2022 · J5 · Original problem · DMOJ

Problem Description

Ron wants to build a square pool in his square NN-by-NN yard, but his yard contains TT trees. Your job is to determine the side length of the largest square pool he can build.

Input Specification

The first line of input will be an integer NN with N≥2N\geq2. The second line will be the positive integer TT where T<N2T < N^2. The remaining input will be TT lines, each representing the location of a single tree. The location is given by two positive integers, RR and then CC, separated by a single space. Each tree is located at row RR and column CC where rows are numbered from top to bottom from 11 to NN and columns are numbered from left to right from 11 to NN. No two trees are at the same location.

The following table shows how the available 15 marks are distributed.

Marks AwardedLength/Width of YardNumber of Trees
3 marksN≤50N \leq 50T=1T=1
5 marksN≤50N \leq 50T≤10T \leq 10
4 marksN≤500 000N \leq 500\,000T≤10T \leq 10
3 marksN≤500 000N \leq 500\,000T≤100T \leq 100

Output Specification

Output one line containing MM which is the largest positive integer such that some MM-by-MM square contained entirely in Ron’s yard does not contain any of the TT trees.

Sample Input 1

5 
1 
2 4

Output for Sample Input 1

3

Explanation of Output for Sample Input 1

A picture of the yard is below. The location of the tree is marked by and one of several 33-by-33 squares that do not contain the tree is highlighted. All larger squares contain a tree.

A 5 by 5 grid. The tree is in the second row from the top in the fourth column from the left. The 3 by 3 grid in the bottom left corner is highlighted.

Sample Input 2

15 8 4 7 4 1 14 11 10 6 13 4 4 10 10 3 9 14

Output for Sample Input 2

7

Explanation of Output for Sample Input 2

A picture of the yard is below. The location of each tree is marked by and one of several 77-by-77 squares that do not contain a tree is highlighted. All larger squares contain a tree.