7052.Food Division

Time Limit: 1s Memory Limit: 512MB

There are $n$ children around a round table. For each child, you know the amount of food they currently have and the amount of food they want. The total amount of food in the table is correct.

At each step, a child can give one unit of food to his or her neighbour. What is the minimum number of steps needed?

Input Format(From the terminal/stdin)

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 current amount of food for each child.

The last line has $n$ integers $b_1,b_2,\ldots,b_n$ : the required amount of food for each child.

  • $1 \le n \le 2 \cdot 10^5$
  • $0 \le a_i, b_i \le 10^6$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of steps.

Sample Input

Copy
3
3 5 0
2 4 2
 \n
 · · \n
 · · \n

Sample Output

Copy
2
 \n

Child 1 gives one unit of food to child 3, and child 2 gives one unit of food to child 3.

Source: CSES, Additional Problems II, 1189

Submit

请先 登录

© 2025 FAQs