← 返回 amazon 的题目列表Allocate Limited Inventory by Bid Priority
类型:online_judge
Allocate Limited Inventory
During an Amazon flash sale, customers submit requests for a limited-inventory product. Each request is represented by four integers:
[customerId, quantity, bidAmount, timestamp]
where:
customerId is the customer ID; each customer submits at most one request.
quantity is the requested number of items, with quantity >= 1.
bidAmount is the customer's bid.
timestamp is the request submission time.
Given totalInventory, allocate items according to the following rules:
Requests with higher bids have higher priority.
Among customers with the same bidAmount, allocate in round-robin order by increasing timestamp.
In every round, each customer whose request is not yet fulfilled receives at most one item.
Stop when inventory is exhausted or every request is fulfilled.
If timestamps are equal, preserve the original input order.
Return the IDs of customers who receive zero items, in their original input order.
Input Format
First line: two integers, n totalInventory.
Next n lines: four integers per line: customerId quantity bidAmount timestamp.
Output Format
Print the list of customer IDs that received no items, for example [4, 7]. Print [] if every customer receives at least one item.
Example
Input:
4 18
1 5 5 0
2 7 8 1
3 7 5 1
4 10 3 3
Output:
[4]
Constraints
1 <= n <= 100000
0 <= totalInventory <= 10^9
1 <= quantity, bidAmount <= 10^9
0 <= timestamp <= 10^9
Example
Input
4 18
1 5 5 0
2 7 8 1
3 7 5 1
4 10 3 3
Output
[4]