#BS0000135. Thời điểm màn hình bị hỏng (Monitor)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thời điểm màn hình bị hỏng (Monitor)
Monitor
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An monitor initially has all pixels working. You are given pixels: pixel permanently becomes broken at time , and each position appears at most once. The monitor is considered broken at the first time any contiguous block consists entirely of broken pixels. Find that time, or output -1 if this never happens.
Input
The first line contains . Each of the next lines contains . Row and column indices are 1-based.
Output
Print the earliest failure time, or -1 if the required square never appears.
Subtasks
- Subtask 1 (20 points): ; ; $1\le k\le\min(n,m);\ 0\le q\le nm;\ 1\le x_i\le n;\ 1\le y_i\le m;\ 0\le t_i\le10^9$; all pixel coordinates are distinct.
- Subtask 2 (30 points): ; ; $1\le k\le\min(n,m);\ 0\le q\le nm;\ 1\le x_i\le n;\ 1\le y_i\le m;\ 0\le t_i\le10^9$; all pixel coordinates are distinct.
- Subtask 3 (50 points): ; ; $1\le k\le\min(n,m);\ 0\le q\le nm;\ 1\le x_i\le n;\ 1\le y_i\le m;\ 0\le t_i\le10^9$; all pixel coordinates are distinct.
Examples
Input
2 3 2 5
2 1 8
2 2 8
1 2 1
1 3 4
2 3 2
Output
8
Explanation
At time , fails; at time , ; at time , . These do not form a full square. At time , and also fail, so form a completely broken square. None exists before time , hence output 8.