← 返回 capitalone 的题目列表Warehouse Package Allocation with Closures and Reset
类型:online_judge
Problem: Warehouse Package Allocation with Closures and Reset
You have n warehouses with remaining capacities capacity (length n) and an operation log dailyLogs.
capacity[i] is the current remaining capacity of warehouse i (initially given).
Each log entry is either:
"PACKAGE": one package arrives and must be allocated.
"CLOSURE idx": warehouse idx is closed and will never accept packages afterward.
Allocation rules
Maintain a pointer p, initially 0. For each PACKAGE, starting from p, scan warehouses in increasing index with wrap-around.
A warehouse i can accept a package if it is not closed and capacity[i] > 0. Allocate to it, decrement capacity[i], and set the next starting pointer to (i+1) mod n.
If you make a full cycle starting from p and find that all warehouses are either closed or have capacity == 0, perform a reset:
For every non-closed warehouse, reset capacity[i] back to its original initial capacity.
Then continue allocating the current package (starting from the current pointer p).
Output
Track how many packages each warehouse processed. After all logs, return the index with the maximum processed packages; if tied, return the largest index.
Suggested input format
Line 1: integer n
Line 2: n integers capacity
Line 3: integer m
Next m lines: each is PACKAGE or CLOSURE idx
Constraints (typical)
1 <= n <= 2 * 10^5, m <= 2 * 10^5
Example
Input
3
1 2 1
6
PACKAGE
PACKAGE
CLOSURE 1
PACKAGE
PACKAGE
PACKAGE
Output
2