304427: CF846D. Monitor

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Monitor

题意翻译

## [题目简述] Luba最近买了个显示器,这个显示器是一个n×m的矩形。但是不久之后她发现这个显示器上有些像素不正常工作(可能会成为坏点)。如果屏幕上有一块k*k的区域都是坏点,那么Luba就觉得这个显示器坏了。她知道有q个像素不正常,而且知道它们彻底罢工变成坏点的时间。 请告诉Luba显示器会不会坏掉,如果会请告诉她具体时间。 ## 输入输出格式 ### [输入格式] 第一行输入4个整数:显示器长度n,宽度m,之前提到的判断显示器是否损坏的标志矩形边长k,不正常像素的数量。 在接下来的q行,每行输入3个整数xi,yi,ti,分别代表第i个坏点的纵横坐标和损坏的时间。每个点至多出现一次。 (假设当时间是ti时,第i个点彻底损坏成为坏点) ### [输出格式] 如果显示器不会坏掉,输出“-1”。 否则请给出显示器坏掉的时间。

题目描述

Recently Luba bought a monitor. Monitor is a rectangular matrix of size $ n×m $ . But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square $ k×k $ consisting entirely of broken pixels. She knows that $ q $ pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all $ q $ pixels stopped working).

输入输出格式

输入格式


The first line contains four integer numbers $ n,m,k,q (1<=n,m<=500,1<=k<=min(n,m),0<=q<=n·m) $ — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels. Each of next $ q $ lines contain three integer numbers $ x_{i},y_{i},t_{i} (1<=x_{i}<=n,1<=y_{i}<=m,0<=t<=10^{9}) $ — coordinates of $ i $ -th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once. We consider that pixel is already broken at moment $ t_{i} $ .

输出格式


Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these $ q $ pixels stopped working.

输入输出样例

输入样例 #1

2 3 2 5
2 1 8
2 2 8
1 2 1
1 3 4
2 3 2

输出样例 #1

8

输入样例 #2

3 3 2 5
1 2 2
2 2 1
2 3 5
3 2 10
2 1 100

输出样例 #2

-1

Input

题意翻译

## [题目简述] Luba最近买了个显示器,这个显示器是一个n×m的矩形。但是不久之后她发现这个显示器上有些像素不正常工作(可能会成为坏点)。如果屏幕上有一块k*k的区域都是坏点,那么Luba就觉得这个显示器坏了。她知道有q个像素不正常,而且知道它们彻底罢工变成坏点的时间。 请告诉Luba显示器会不会坏掉,如果会请告诉她具体时间。 ## 输入输出格式 ### [输入格式] 第一行输入4个整数:显示器长度n,宽度m,之前提到的判断显示器是否损坏的标志矩形边长k,不正常像素的数量。 在接下来的q行,每行输入3个整数xi,yi,ti,分别代表第i个坏点的纵横坐标和损坏的时间。每个点至多出现一次。 (假设当时间是ti时,第i个点彻底损坏成为坏点) ### [输出格式] 如果显示器不会坏掉,输出“-1”。 否则请给出显示器坏掉的时间。

加入题单

算法标签: