아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Corral the Cows

시간 제한1초메모리 제한1024 MB

요약
중복을 포함해 최대 500개의 단위 클로버 밭이 주어질 때, 그중 C개 이상을 완전히 포함하는 가장 작은 축에 평행한 정사각형의 한 변 길이를 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 슬라이딩 윈도우, 배열
정답자
아직 제출이 없습니다

문제

Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 ≤ C ≤ 500) clover fields for afternoon treats. The corral's edges must be parallel to the X,Y axes.

FJ's land contains a total of N (C ≤ N ≤ 500) clover fields, each a block of size 1 x 1 and located at with its lower left corner at integer X and Y coordinates each in the range 1..10,000. Sometimes more than one clover field grows at the same location; such a field would have its location appear twice (or more) in the input. A corral surrounds a clover field if the field is entirely located inside the corral's borders.

Help FJ by telling him the side length of the smallest square containing C clover fields.

입력

  • Line 1: Two space-separated integers: C and N
  • Lines 2..N+1: Each line contains two space-separated integers that are the X,Y coordinates of a clover field.

출력

  • Line 1: A single line with a single integer that is length of one edge of the minimum size square that contains at least C clover fields.

예제1

  1. 예제 1

    입력
    3 4
    1 2
    2 1
    4 1
    5 2
    
    예상 출력
    4