#10154. [HAOI2008] 糖果传递

    ID: 10154 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2008河南各省省选前缀和

[HAOI2008] 糖果传递

Problem Description

There are nn children sitting in a circle, each with aia_i candies. Each child can only pass candies to their left and right neighbors. The cost of passing one candy each time is 11.

Input Format

The first line contains nn. Each of the next nn lines contains aia_i.

Output Format

Output the minimum cost to make all children have the same number of candies.

4
1
2
5
4
4

Hint

Constraints: For 100%100\% of the testdata, 1≤n≤1061 \le n \le 10^6, 1≤ai≤1.5×1091 \le a_i \le 1.5 \times 10^9, and ∑i=1nai\sum_{i=1}^{n}{a_i} is a multiple of nn.

Translated by ChatGPT 5