Tashu
InterviewTime limit1sMemory limit1024 MB
Given current and target bike counts per station, find the minimum number of single-bike moves to reach the target counts.
- Level
Easy3 of 10
- Topics
- Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Tashu is a public bike rental service run by Daejeon city. Citizens can rent a bike from an unattended rental station and must return it to an unattended rental station when they finish. The bike does not have to go back to the station where it was rented. It can be returned to any station.
The city installed rental stations and placed bikes at each station, based on expected demand, then started the service. Some time later, to improve service quality, the city suspended Tashu and had every bike returned to a station. Fortunately no bike was lost, but the number of bikes at each station became .
Youngwoo, who works for the Daejeon city government, wants to restore the number of bikes at each station to before service resumes. Youngwoo can pick up one bike at station on foot and carry it to station . Find the minimum number of bikes Youngwoo must move.
Input
The first line contains an integer .
The second line contains integers separated by spaces.
The third line contains integers separated by spaces.
The sum equals .
Output
Print the minimum number of times bikes must be moved so that the number of bikes at each station becomes .