#P2125. 图书馆书架上的书
图书馆书架上的书
Description
There are bookshelves in a circle. The shelf behind shelf is shelf , the shelf behind shelf is shelf , …, the shelf behind shelf is shelf , and the shelf behind shelf is shelf . Shelf has books. To make the library look nicer, WZF shenniu asks SY to move books so that every shelf ends up with the same number of books. Because the total number of moved books might be large, SY is only allowed to move books from a shelf to its two adjacent shelves. What is the minimum number of books SY needs to move?
Input Format
There are lines. The first line contains a positive integer . The second line contains non-negative integers, where the -th is .
Output Format
Output lines.
The first line contains a positive integer , the minimum total number of books SY needs to move.
Then output lines. In the -th line, output two integers and , meaning SY moves books and books from shelf to the shelf in front of it and the shelf behind it, respectively.
5
15 7 11 3 14
12
2 3
-3 0
0 1
-1 -6
6 -2
Hint
Constraints and Notes
For all testdata, , and is odd; .
If is negative, it means SY moves books from the shelf in front of shelf onto shelf .
Similarly, if is negative, it means SY moves books from the shelf behind shelf onto shelf .
Translated by ChatGPT 5
京公网安备 11011102002149号