IRCTC Waitlist Promotion
An IRCTC-style railway booking system keeps a waitlist. When seats free up, passengers are confirmed by priority: senior citizens first, then by earliest booking time. Given a stream of seat-release events and the waitlist, output the order in which passengers get confirmed.
Problem
Given a list of waitlisted passengers, each with (bookingTime, isSenior), and an integer S of seats that free up one at a time, return the passenger indices confirmed in order. Higher priority = senior over non-senior; ties broken by smaller bookingTime; further ties by smaller index.
Input
An array of n passengers (1 ≤ n ≤ 10^5) each as (bookingTime in [0,10^9], isSenior boolean), and an integer S (0 ≤ S ≤ n).
Output
An array of up to S passenger indices in confirmation order.
Constraints
- 1 ≤ n ≤ 100,000
- 0 ≤ S ≤ n
- Priority: senior first; then earliest bookingTime; then smallest index
Examples
Example 1
Input
passengers = [(100,false),(90,true),(95,false)], S = 2
Output
[1, 2]
Passenger 1 is senior → confirmed first. Among non-seniors, index 2 booked at 95 < index 0 at 100, so index 2 is next.
Example 2
Input
passengers = [(50,false),(50,false)], S = 1
Output
[0]
Neither is senior and both booked at 50; the tie breaks on smaller index 0.