CF1237G.Balanced Distribution
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n friends living on a circular street. The friends and their houses are numbered clockwise from 0 to n−1 .
Initially person i has ai stones. The friends want to make the distribution of stones among them perfectly balanced: everyone should possess the same number of stones.
The only way to change the distribution of stones is by conducting meetings. During a meeting, people from exactly k consecutive houses (remember that the street is circular) gather at the same place and bring all their stones with them. All brought stones may be redistributed among people attending the meeting arbitrarily. The total number of stones they possess before the meeting and after the meeting must stay the same. After the meeting, everyone returns to their home.
Find a way to make the distribution of stones perfectly balanced conducting as few meetings as possible.
输入格式
The first line contains two integers n and k ( 2≤k<n≤105 ), denoting the number of friends and the size of each meeting.
The second line contains n integers a0,a1,…,an−1 ( 0≤ai≤104 ), denoting the number of stones people initially have.
The sum of all ai is divisible by n .
输出格式
Output the minimum number of meetings m ( m≥0 ), followed by m descriptions of meetings in chronological order.
The i -th description must consist of an integer si ( 0≤si<n ), followed by k non-negative integers bi,0,bi,1,…,bi,k−1 ( bi,j≥0 ). Such a description denotes a meeting of people si,(si+1)modn,…,(si+k−1)modn , and bi,j denotes the number of stones person (si+j)modn must have after the i -th meeting. The sum of bi,j must match the total number of stones owned by these people before the i -th meeting.
We can show that a solution exists for any valid input, and any correct output contains at most 107 non-whitespace characters.
输入输出样例
输入#1
6 3 2 6 1 10 3 2
输出#1
3 2 7 3 4 5 4 4 2 1 4 4 4
输入#2
11 4 1 0 1 0 0 4 4 2 4 3 3
输出#2
3 3 2 2 2 2 8 2 2 2 5 10 2 2 2 2
说明/提示
In the first example, the distribution of stones changes as follows:
- after the first meeting: 2 6 7 3 4 2 ;
- after the second meeting: 4 2 7 3 4 4 ;
- after the third meeting: 4 4 4 4 4 4 .
In the second example, the distribution of stones changes as follows:
- after the first meeting: 1 0 1 2 2 2 2 2 4 3 3 ;
- after the second meeting: 5 0 1 2 2 2 2 2 2 2 2 ;
- after the third meeting: 2 2 2 2 2 2 2 2 2 2 2 .