オムロンプログラミングコンテスト2025 #2(AtCoder Beginner Contest 432)
F
Candy Redistribution
AtCoder
⌀ 2273
原题
← DG →
翻译中…

Problem Statement

翻译中…

There are $N$ children, numbered $1$ to $N$.

翻译中…

Child $i$ has $A_i$ candies.

翻译中…

Your goal is to execute the following operation as few times as possible so that eventually all $N$ children have the same number of candies.

翻译中…
  • Choose two distinct children $x,y$, and choose a positive integer $z$ not exceeding the number of candies child $x$ has. Take $z$ candies from child $x$ and give them to child $y$.
翻译中…

Determine whether there exists a sequence of operations such that eventually all $N$ children have the same number of candies. If it exists, find one such sequence with the minimum number of operations.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 20$
  • $1 \leq A_i \leq 10^8$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 \dots A_N

翻译中…

Output

翻译中…

If there is no sequence of operations such that eventually all $N$ children have the same number of candies, output -1.

翻译中…

If it exists, output one with the minimum number of operations in the following format:

翻译中…

q
x_1 y_1 z_1
\vdots
x_q y_q z_q

翻译中…

Here, $q$ represents the number of operations, and $x_i,y_i,z_i$ represent the values of $x,y,z$ chosen in the $i$-th operation.

翻译中…

If there are multiple solutions, outputting any of them will be considered correct.

翻译中…

样例

Input #1
4
1 7 4 8
Output #1
3
2 3 1
2 4 1
4 1 4
In this sample output, the operations are executed as follows: 1. Take $1$ candy from child $2$ and give it to child $3$. Immediately after this, the number of candies each child has is $1,6,5,8$. 2. Take $1$ candy from child $2$ and give it to child $4$. Immediately after this, the number of candies each child has is $1,5,5,9$. 3. Take $4$ candies from child $4$ and give them to child $1$. Immediately after this, the number of candies each child has is $5,5,5,5$. Eventually, all $N$ children have exactly five candies each.
Input #2
2
100 3
Output #2
-1
题目信息
题号
abc432_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。