Mineral Extraction
Time limit3sMemory limit512 MB
Find the largest number of leading batches, and then the most robots from the next batch, that can be placed on the grid with at most q robots per cell.
- Level
Hard8 of 10
- Topics
- Graph, Binary search
- Solved
- No attempts yet
Statement
A project is underway to develop a planet in a neighboring star system. Several batches of robots will be sent to the planet to mine minerals.
The mining area is a grid rectangle of size by , with cells from to . Some cells contain specialist bases, and robot batches are delivered to these bases. There are bases in total, and the -th base is in the cell .
The -th batch is delivered to base and contains robots. Each robot in the batch has mobility . Once a batch arrives at its base, each robot moves across the surface from the base to some cell. A robot with mobility may move at most times, each time to one of the eight neighboring cells (see Fig. 1).

After the robots from all delivered batches are placed, they are activated and start mining. During movement, any number of robots may share a cell. However, after activation, no cell may hold more than robots.
Input
The management has information about batches that can be sent to the planet in sequence. After all batches are delivered, limited mobility may make it impossible to place the robots so that no cell holds more than of them. Therefore management chooses the first batches () to be fully delivered to their bases. If , management also accepts of the robots from the next batch, the -th one ().
Management maximizes first and then maximizes .
Output
The first line contains , , , and , where , , and . The next lines each contain the coordinates and of a base, where and . The next line contains the number of batches , where . The next lines each contain , , and , where , , and .
Hint
In the sample, the whole first batch is accepted, and 7 robots from the second batch are accepted as well. Fig. 2 shows a placement where every cell holds at most one robot. Bases are drawn as circles. Cells with robots from base 1 are hatched vertically, and cells with robots from base 2 are gray.
