← 返回 amazon 的题目列表Inventory Allocation
类型:online_judge
Problem: Inventory Allocation
You are given a list of inventory requests. Each request has the following format:
[customerId, quantity, bidAmount, timestamp]
where:
customerId is the customer's ID.
quantity is the number of items requested by the customer.
bidAmount is the customer's bid.
timestamp is the request submission time.
Given totalInventory, allocate items according to the following rules:
A higher bidAmount has higher priority.
For customers with the same bidAmount, allocate items in round-robin order by increasing timestamp.
Within the same bid group, in each round, each customer with remaining demand receives at most one item.
Allocation continues until either:
the customer's requested quantity is fulfilled; or
the total inventory is exhausted.
Lower bids are considered only after all higher bids have been processed.
Return the IDs of customers who receive no items.
For deterministic output, return customer IDs in ascending order.
Input Format
n totalInventory
customerId1 quantity1 bidAmount1 timestamp1
customerId2 quantity2 bidAmount2 timestamp2
...
customerIdn quantityn bidAmountn timestampn
Output Format
Print a Python/JSON-style list containing the customer IDs who receive no items, sorted in ascending order.
Constraints
Assume:
1 <= n <= 10^5
1 <= customerId <= 10^9
1 <= quantity <= 10^9
1 <= bidAmount <= 10^9
0 <= timestamp <= 10^9
0 <= totalInventory <= 10^18
All customerIds are unique.
Example
Input:
4 18
1 5 5 0
2 7 8 1
3 7 5 1
4 10 3 3
Output:
[4]
Explanation:
Customer 2 has the highest bid and receives all 7 requested items first. Inventory left: 11.
Customers 1 and 3 have the same bid, so they are processed in round-robin order by timestamp. Both receive at least one item.
Inventory is exhausted before customer 4, who has a lower bid, can receive any item.
Therefore, the answer is [4].
Example
Input
4 18
1 5 5 0
2 7 8 1
3 7 5 1
4 10 3 3
Output
[4]