AmazonOA #132
Compute Remaining Tasks
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesBinary Search
Tasks are executed in order, and an unfinished task continues across shifts. The rules are completed according to the source's first two examples: when a shift finishes all tasks, output 0 and discard that shift's excess time, and the next shift starts again from the first task of the whole batch; there is no restart within the same shift.
Input
The first line contains n m (1..200000), followed by two lines with n task durations and m shift durations respectively, all in 1..10⁹.
Output
Output the m remaining task counts in shift order.
Example 1
Input:
3 3
1 4 4
9 1 4
Output:
0 2 1
Example 2
Input:
5 5
1 2 4 1 2
3 10 1 1 1
Output:
3 0 4 4 3
Example 3
Input:
5 5
2 4 5 1 1
1 5 1 5 2
Output:
5 3 3 1 0
Example notes
Example 1: the first shift finishes exactly, so output 0; after the restart, finishing the first task leaves 2, then finishing the second leaves 1. Example 2: the first shift finishes the first two tasks, leaving 3; the second shift finishes the rest and discards the excess; for the new batch the next three shifts leave 4, 4 and 3. Example 3: the cumulative times used are 1, 6, 7, 12, 14, leaving 5, 3, 3, 1, 0 respectively.
Editorial
Loading solution…