Weighted Traffic Shard Router

A gateway shard router splits incoming traffic proportionally to shard weights. Each shard i advertises weights[i] (positive). The router builds prefix sums pref[i] = weights[0] + ... + weights[i] with total T = pref[n-1]. Every ticket is an integer t with 1 <= t <= T. The router must return the smallest shard index i with pref[i] >= t using binary search.

You are given weights and a batch of deterministic tickets tickets. For each ticket deterministically map it to a shard with prefix sums plus binary search and return the selected indices in order. No randomness may be used. The prefix array must be preserved and each ticket resolved with lower-bound binary search.

Return an array ans where ans[k] is the shard index for tickets[k]. If tickets is empty return [].

Examples
Input: [[1,3],[1,2,3,4]]
Output: [0,1,1,1]
Hints

Weighted Traffic Shard Router

A gateway shard router splits incoming traffic proportionally to shard weights. Each shard `i` advertises `weights[i]` (positive). The router builds prefix sums `pref[i] = weights[0] + ... + weights[i]` with total `T = pref[n-1]`. Every ticket is an integer `t` with `1 <= t <= T`. The router must return the smallest shard index `i` with `pref[i] >= t` using binary search.