Mining
Time limit2sMemory limit256 MB
Given a grid of mineral strengths with air only on the top, left, and right faces, find the smallest performance D so that at least K minerals can be removed in some order.
- Level
Hard8 of 10
- Topics
- Binary search, BFS, Implementation, Array
- Solved
- No attempts yet
Problem
A mine of rows and columns rests on the ground. It is made of minerals of size , and the mineral in row , column has strength .

The top face of the mine, its left face and its right face touch air. Its bottom face rests on the ground.
You want to mine these minerals with a mining machine. The mining machine can pick any mineral that has at least one face touching air and mine it. A mineral whose four faces all touch the ground or other minerals cannot be mined. Once a mineral is mined, air fills the square it occupied, so minerals further inside become exposed.
A machine of performance can mine only the minerals whose strength is at most . Find the smallest that lets the machine mine at least minerals.
Input
The first line contains , and . (, )
Each of the next lines gives the strengths of one row of minerals, from the top row down. Line contains integers separated by spaces. ()
Output
Print the smallest performance that lets the machine mine at least minerals.