Cramming for Finals

시간 제한4초메모리 제한2048 MB

요약
r×c 격자에 n개의 점유된 자리가 주어지고 반경 d가 주어질 때, 거리 d 이내의 점유 자리 수가 최소인 빈 자리를 찾는다.
난이도

어려움10점 중 8점

유형
기하, 완전 탐색, 수학, 구현
정답자
아직 제출이 없습니다

문제

It's final exam season and Ashley is heading to her favorite library to cram for finals.

The library has a dedicated floor for studying where there are rr rows of cc tables evenly spaced. Each table only has room for one student, and some students have already arrived and claimed their favorite tables.

Because the floor is usually very quiet, it is possible to hear sounds from other students who are nearby -- for example, frustrated typing on a laptop keyboard or nervous leg shaking. Specifically, if one student is studying at the table in row i_1i\_1 and column j_1j\_1, and another student is studying at the table in row i_2i\_2 and column j_2j\_2, it is possible for the two students to hear sounds from each other if and only if (i_1−i_2)2+(j_1−j_2)2≤d\sqrt{(i\_1 - i\_2)^2 + (j\_1 - j\_2)^2} \le d.

With this, Ashley wants to find an empty table where she can hear as few other students as possible. Compute the minimum number of students that Ashley can hear if she selects her table optimally.

입력

The first line of input has four integers rr, cc (2≤r,c≤1092 \leq r, c \leq 10^9), dd (1≤d≤2,5001 \leq d \leq 2\\, 500), and nn (1≤n≤1031 \leq n \leq 10^3 and n≤r⋅c−1n \leq r \cdot c - 1).

Each of the next nn lines contains two integers ii (1≤i≤r1 \le i \le r) and jj (1≤j≤c1 \le j \le c), indicating that a student is studying at the table at row ii and column jj. It is guaranteed that no two students are sitting at the same table.

출력

Output a single integer, which is the minimum number of students that Ashley can hear if she selects her table optimally.

예제1

  1. 예제 1

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