Driver Rebalancing Across City Corridors

Medium
ArrayPrefix SumGreedyUberHireUp
A city has N zones arranged in a straight line and numbered 1 through N. Zone i currently has current[i] available drivers, while target[i] is the desired number of drivers in that zone. In one move, you may move one driver from a zone to either adjacent zone. Moving a driver across one zone boundary costs 1. A driver may cross several boundaries through several moves. The total number of current drivers equals the total target, so it is always possible to reach the target distribution. Find the minimum total movement cost. Input format: - First line: N - Second line: N integers current[1], current[2], ..., current[N] - Third line: N integers target[1], target[2], ..., target[N] Print a single integer: the minimum total movement cost. The answer can exceed a 32-bit integer.

Constraints

1 <= N <= 2 * 10^5
0 <= current[i], target[i] <= 10^9
sum(current) = sum(target) <= 10^13

Sample tests

Sample 1

Sample 2

Sign in to submit