CF1237G.Balanced Distribution
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
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.
有 n 位朋友住在一条环形街道上。朋友及其房屋按顺时针方向编号为 0 到 n−1。
初始时,第 i 位朋友拥有 ai 颗石头。朋友们希望使石头的分布达到完全均衡:即每人拥有的石头数量相同。
改变石头分布的唯一方式是举行会议。在一次会议中,恰好来自 k 个连续房屋(注意:街道是环形的)的人聚集在同一地点,并携带他们所有的石头。所有带来的石头可以在与会者之间任意重新分配,但会议前后这些与会者所拥有的石头总数必须保持不变。会议结束后,所有人返回各自家中。
请找出一种方案,通过尽可能少的会议次数,使石头分布达到完全均衡。
输入格式
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.
第一行包含两个整数 n 和 k(2≤k<n≤105),分别表示朋友的数量以及每次聚会的人数。
第二行包含 n 个整数 a0,a1,…,an−1(0≤ai≤104),表示每个人初始拥有的石头数量。
所有 ai 的总和能被 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.
输出最少的会议次数 m(m≥0),随后按时间顺序输出 m 场会议的描述。
第 i 场会议的描述必须包含一个整数 si(0≤si<n),后接 k 个非负整数 bi,0,bi,1,…,bi,k−1(bi,j≥0)。该描述表示一场由人员 si,(si+1)modn,…,(si+k−1)modn 参加的会议,且 bi,j 表示在第 i 场会议结束后,人员 (si+j)modn 所拥有的石子数量。所有 bi,j 的和必须等于这些人员在第 i 场会议开始前拥有的石子总数。
可以证明:对任意合法输入均存在解,且任意正确输出所含非空白字符数至多为 107。
输入输出样例
输入#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.
在第一个例子中,石头的分布变化如下:
- 第一次会面后:2 6 7 3 4 2;
- 第二次会面后:4 2 7 3 4 4;
- 第三次会面后:4 4 4 4 4 4。
在第二个例子中,石头的分布变化如下:
- 第一次会面后:1 0 1 2 2 2 2 2 4 3 3;
- 第二次会面后:5 0 1 2 2 2 2 2 2 2 2;
- 第三次会面后:2 2 2 2 2 2 2 2 2 2 2。
输入解题思路,AI测评打分。不知道怎么写?