Loading...
Loading...
You are given supply identical units and a list requests, where requests[i] = [id, priority, amount, order]: id identifies the request, priority is its priority, amount is how many units it asks for, and order is its arrival position.
Units are handed out as follows:
priority are served before requests with a lower priority.priority are served round robin: repeatedly walk that priority group in increasing order and give one unit to each request that still wants more, until the supply runs out or every request in the group has received its full amount.Return the id of every request that did not receive its full amount, sorted in increasing order. Return an empty array if every request is fully served.
Input: requests = [[1, 3, 1, 1],
[2, 4, 2, 2]]
supply = 1
Output: [1, 2]
Explanation: Request 2 has the higher priority, so it is served first and takes
the single unit — one short of the 2 it wanted. Nothing is left for request 1,
which receives none of the 1 unit it wanted. Both fall short.
Input: requests = [[1, 3, 2, 1],
[2, 3, 2, 2],
[3, 3, 1, 3]]
supply = 4
Output: [2]
Explanation: All three share priority 3. The first pass gives one unit each
(3 units used, 1 left) and completes request 3. The second pass gives the last
unit to request 1, completing it. Request 2 holds 1 of its 2 units when the
supply runs out.
Input: requests = [[5, 2, 3, 1],
[6, 2, 1, 2]]
supply = 10
Output: []
Explanation: The supply covers the total demand of 4 units, so every request is
fully served.
requests.length ≤105requests[i].length =4id, priority, amount, order ≤109id values are distinct.order values are distinct.supply ≤109