#P1413. Nut Bowling
Nut Bowling
Nut Bowling
In this problem, you are given a scenario inspired by the game PVZ. In this game, zombies start appearing at the right side of a grid and move leftwards every second. The grid has 6 rows and 60 columns. A zombie appears at column 60 at its appearance time and then moves one column to the left each second.
A player can at any moment place a nut at the leftmost cell (column 1) of any row. When a nut is placed on a row, it instantly kills all zombies currently on that row. However, if a zombie reaches column 1 and is not eliminated before it moves left (i.e. if it would leave the grid), the game is over.
For each zombie, you are given its appearance time T and the row R in which it appears. Once a zombie appears, it will be on the board from time T until time T + 59 (because it starts at column 60 and reaches column 1 at time T + 59).
Your task is to determine the minimum number of nuts that need to be placed such that every zombie is killed before it would move off the board. In each row, planting a nut at time t will kill all zombies in that row that satisfy T ≤ t ≤ T + 59.
This can be solved by considering each row separately and using a greedy algorithm to cover the time intervals [T, T+59] for each zombie with as few points (nut placements) as possible.
Mathematically, for each zombie, the kill interval is given by:
$$ [T, T+59] $$You must cover all these intervals in each row with as few points as possible. Output the minimum total number of nuts required.
inputFormat
The first line contains an integer n
representing the number of zombies.
Each of the following n
lines contains two integers: the appearance time T
(0 ≤ T ≤ 109) and the row number R
(1 ≤ R ≤ 6) of a zombie.
outputFormat
Output a single integer: the minimum number of nuts required to kill all zombies.
sample
3
1 1
50 1
2 2
2