CF1237G.Balanced Distribution

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are nn friends living on a circular street. The friends and their houses are numbered clockwise from 00 to n−1n-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.

有 nn 位朋友住在一条环形街道上。朋友及其房屋按顺时针方向编号为 00 到 n−1n-1。

初始时,第 ii 位朋友拥有 aia_i 颗石头。朋友们希望使石头的分布达到完全均衡:即每人拥有的石头数量相同。

改变石头分布的唯一方式是举行会议。在一次会议中,恰好来自 kk 个连续房屋(注意:街道是环形的)的人聚集在同一地点,并携带他们所有的石头。所有带来的石头可以在与会者之间任意重新分配,但会议前后这些与会者所拥有的石头总数必须保持不变。会议结束后,所有人返回各自家中。

请找出一种方案,通过尽可能少的会议次数,使石头分布达到完全均衡。

输入格式

The first line contains two integers nn and kk (2≤k<n≤1052 \le k \lt n \le 10^5), denoting the number of friends and the size of each meeting.

The second line contains nn integers a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1} (0≤ai≤1040 \le a_i \le 10^4), denoting the number of stones people initially have.

The sum of all aia_i is divisible by nn.

第一行包含两个整数 nn 和 kk(2≤k<n≤1052 \le k \lt n \le 10^5),分别表示朋友的数量以及每次聚会的人数。

第二行包含 nn 个整数 a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1}(0≤ai≤1040 \le a_i \le 10^4),表示每个人初始拥有的石头数量。

所有 aia_i 的总和能被 nn 整除。

输出格式

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

The ii-th description must consist of an integer sis_i (0≤si<n0 \le s_i \lt n), followed by kk non-negative integers bi,0,bi,1,…,bi,k−1b_{i, 0}, b_{i, 1}, \ldots, b_{i, k-1} (bi,j≥0b_{i, j} \ge 0). Such a description denotes a meeting of people si,(si+1) mod n,…,(si+k−1) mod ns_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) mod n(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.

输出最少的会议次数 mm(m≥0m \ge 0),随后按时间顺序输出 mm 场会议的描述。

第 ii 场会议的描述必须包含一个整数 sis_i(0≤si<n0 \le s_i \lt n),后接 kk 个非负整数 bi,0,bi,1,…,bi,k−1b_{i, 0}, b_{i, 1}, \ldots, b_{i, k-1}(bi,j≥0b_{i, j} \ge 0)。该描述表示一场由人员 si,(si+1) mod n,…,(si+k−1) mod ns_i, (s_i + 1) \bmod n, \ldots, (s_i + k - 1) \bmod n 参加的会议,且 bi,jb_{i,j} 表示在第 ii 场会议结束后,人员 (si+j) mod n(s_i + j) \bmod n 所拥有的石子数量。所有 bi,jb_{i, j} 的和必须等于这些人员在第 ii 场会议开始前拥有的石子总数。

可以证明:对任意合法输入均存在解,且任意正确输出所含非空白字符数至多为 10710^7。

输入输出样例

  • 输入#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}.

在第一个例子中,石头的分布变化如下:

  • 第一次会面后:22 66 7\mathbf{7} 3\mathbf{3} 4\mathbf{4} 22;
  • 第二次会面后:4\mathbf{4} 2\mathbf{2} 77 33 44 4\mathbf{4};
  • 第三次会面后:44 4\mathbf{4} 4\mathbf{4} 4\mathbf{4} 44 44。

在第二个例子中,石头的分布变化如下:

  • 第一次会面后:11 00 11 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 44 33 33;
  • 第二次会面后:5\mathbf{5} 00 11 22 22 22 22 22 2\mathbf{2} 2\mathbf{2} 2\mathbf{2};
  • 第三次会面后:2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 22 22 22 22 22 22 2\mathbf{2}。

输入解题思路,AI测评打分。不知道怎么写?

首页