|| ||Code Submission Evaluation System
CSES Problem Set
Task | Statistics
CSES - Food DivisionCSES - Food Division
|Time limit:||1.00 s
||Memory limit:||512 MB|
There are $n$ children around a round table. For each child, you know the amount of food they want and the amount of food they currently have. The total amount of food in the table is correct.
At each step, a child can give one unit of food to their neighbour. What is the minimum number of steps needed?
The first input line contains an integer $n$: the number of children.
The next line has $n$ integers $a_1,a_2,\ldots,a_n$: the required amount of food for each child.
The last line has $n$ integers $b_1,b_2,\ldots,b_n$: the current amount of food for each child.
Print one integer: the minimum number of steps.
- $1 \le n \le 5 \cdot 10^5$
- $1 \le a_i \le 10^9$
- $1 \le b_i \le 10^9$
3 5 0
2 4 2
Explanation: Child 1 gives one unit of food to child 3, and child 2 gives one unit of food to child 3.