Distributing Seats
Time limit2sMemory limit512 MB
Each passenger accepts a seat in a row within s_i rows of their assigned row but any column; maximize how many passengers get a seat.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Intervals, Implementation
- Solved
- No attempts yet
Problem
An airline called Divided Airlines has recently made the news due to their tendency to overbook their flights rather aggressively. For some flights, they even resorted to dragging passengers out from the plane! This was of course not very popular, so they decided to "resolve" the issue by making the seating assignments very chaotic (airlines do like unnecessary complexity).
A particular flight has passengers. The seats are divided into rows each containing seats. Every passenger is assigned to some particular seat located at row and column . However, some passengers may be assigned to the same seat.
Of course, passengers are usually okay with sitting somewhere else than their assigned seat, but they may still want to be somewhat close to their original seat. Perhaps they want to be able to speak to their friends, or sit close to their overhead luggage. More specifically, passenger accepts sitting at most rows away from the row on their ticket.
Due to budget reasons, you decided to travel on a Divided flight. As expected, all the passengers assigned to an overbooked seat started to fight with each other, moving around in complex ways and causing a long delay. You proposed a fair resolution: you will construct a seat assignment which takes into account how far the passengers accept to sit from their assigned seats so that as many passengers as possible get a seat. Now, all that remains is to actually find this assignment.
Input
The input consists of:
- one line with the integers , and (), the number of passengers, rows and columns in the flight.
- lines with the integers and (, , ). The 'th line has the assigned row and column , and maximum distance of the 'th passenger. The maximum distance is given in rows.
Output
Output the maximum number of passengers that can be assigned a seat in an optimal assignment.