cswork / OA打开练习工作台

AmazonOA #176

Find Minimum Time to Create Beautiful Canvas

估计中等可在线判题

考点(AI 标注)二分查找前缀和区间

On a white n×m canvas, one given cell is painted black every minute, and each cell appears exactly once. Find the minute at which a fully painted k×k square first exists.

输入格式

The first line contains n m k, followed by n×m lines of 1-indexed coordinates, all distinct. 1≤n,m≤750; 1≤k≤min(n,m).

输出格式

Output a single integer, the answer.

样例 1

输入:

1 1 1
1 1

输出:

1

样例 2

输入:

2 2 2
1 1
2 2
1 2
2 1

输出:

4

样例 3

输入:

2 3 2
1 1
1 2
2 1
2 2
1 3
2 3

输出:

4

样例说明

The answers to the three examples are 1, 4 and 4; in the third example the left square is completed first.