CF1237G.Balanced Distribution

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn friends living on a circular street. The friends and their houses are numbered clockwise from 00 to n1n-1 .

Initially person ii has aia_i 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 kk 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 nn and kk ( 2k<n1052 \le k < n \le 10^5 ), denoting the number of friends and the size of each meeting.

The second line contains nn integers a0,a1,,an1a_0, a_1, \ldots, a_{n-1} ( 0ai1040 \le a_i \le 10^4 ), denoting the number of stones people initially have.

The sum of all aia_i is divisible by nn .

输出格式

Output the minimum number of meetings mm ( m0m \ge 0 ), followed by mm descriptions of meetings in chronological order.

The ii -th description must consist of an integer sis_i ( 0si<n0 \le s_i < n ), followed by kk non-negative integers bi,0,bi,1,,bi,k1b_{i, 0}, b_{i, 1}, \ldots, b_{i, k-1} ( bi,j0b_{i, j} \ge 0 ). Such a description denotes a meeting of people si,(si+1)modn,,(si+k1)modns_i, (s_i + 1) \bmod n, \ldots, (s_i + k - 1) \bmod n , and bi,jb_{i,j} denotes the number of stones person (si+j)modn(s_i + j) \bmod n must have after the ii -th meeting. The sum of bi,jb_{i, j} must match the total number of stones owned by these people before the ii -th meeting.

We can show that a solution exists for any valid input, and any correct output contains at most 10710^7 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: 22 66 7\mathbf{7} 3\mathbf{3} 4\mathbf{4} 22 ;
  • after the second meeting: 4\mathbf{4} 2\mathbf{2} 77 33 44 4\mathbf{4} ;
  • after the third meeting: 44 4\mathbf{4} 4\mathbf{4} 4\mathbf{4} 44 44 .

In the second example, the distribution of stones changes as follows:

  • after the first meeting: 11 00 11 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 44 33 33 ;
  • after the second meeting: 5\mathbf{5} 00 11 22 22 22 22 22 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} ;
  • after the third meeting: 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 22 22 22 22 22 22 2\mathbf{2} .
首页