A company is going public and has a fixed number of shares to allocate to investors who submitted bids. Each bid contains a price, a timestamp, and the number of shares requested. Shares must be allocated according to the following rules:
Higher-price bids are satisfied first. Among bids at the same price, earlier timestamps (smaller values) are served first.
Within a price-time group, shares are distributed round-robin: one share to each bidder in turn until either all requested shares at that price are exhausted or the remaining shares are allocated.
A bidder who receives at least one share is considered successful; bidders who receive none are unsuccessful.
The process stops when either all shares are allocated or no more bids can be satisfied.
You are given:
An integer totalShares (1 ≤ totalShares ≤ 10^9) representing the total shares to allocate.
A list bids where each element is a tuple (userId, price, timestamp, sharesRequested) with: