Seating
Time limit1sMemory limit128 MB
Track seats in a row under arrivals needing the lowest block of p empty seats and range departures; count the parties turned away.
- Level
Medium7 of 10
- Topics
- Segment tree, Binary search, Array, Greedy
- Solved
- No attempts yet
Problem
To earn some extra money, the cows have opened a milkshake restaurant in their barn. The restaurant has seats in a single row (), and every seat is empty at the start of the day.
Over the course of the day, events happen in sequence (). Each event is one of two kinds:
- A party of size arrives (). Bessie wants to seat the whole party in a block of consecutive empty seats. If this is possible, she seats them at the lowest-numbered position where they fit. If it is impossible, the party is turned away.
- A range is given (), and everybody sitting in that range of seats leaves (those seats all become empty).
Count the total number of parties that are turned away during the day.
Input
- Line 1: Two space-separated integers and .
- Next lines: Each line describes one event. A line
A pmeans a party of size arrives; a lineL a bmeans every customer in the seat range leaves.
Output
- Line 1: The number of parties that are turned away.
Notes
Here is a walkthrough of the first example. There are 10 seats and 4 events. First, a party of 6 arrives and takes seats 1–6. Then everybody in seats 2–4 leaves. Next, a party of 5 arrives, but no block of 5 consecutive empty seats exists, so it is turned away. Finally, a party of 2 arrives and takes the empty seats 2–3. Only the third party is turned away.