Division of cats
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka recently bought \(n\) new cats in Auchan. It is known that the \(i\)-th cat weighs \(a_i\) kilograms.
Now our heroes want to divide these cats among themselves. The main thing for them is that the expenses for these cats are distributed equally between the friends. Since the expenses for a cat are proportional to its weight, they want to divide the cats so that the total weight of Zenyk’s cats is equal to the total weight of Marichka’s cats.
Your task is to help them find the desired division.
Input
The first line gives a single integer \(n\) — the number of cats.
The second line gives \(n\) integers \(a_i\) — the weights of the respective cats.
The cats are numbered with integers from 1 to \(n\) inclusive.
Output
If it is impossible to divide the cats correctly, output a single
number -1.
Otherwise, in the first line output the number \(k\) — the number of cats that Zenyk will get.
In the second line output a sequence of \(k\) integers — the indices of Zenyk’s cats. All other cats will be received by Marichka.
If there are several correct distributions, you are allowed to output any of them.
Constraints
\(1 \le n \le 200\),
\(1 \le a_i \le 4\),
\(40\%\) of tests: \(n \le 20\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 4 1 4 3 4 | 3 1 2 4 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Division of cats - Editorial
We are given a set of \(n\) numbers, each from 1 to 4. We need to split this set into two with equal sums.
Clearly, for each possible weight \((1..4)\), we care about how many cats of this weight Zenyk gets. So it is enough to go over all quadruples of numbers \((c_1, c_2, c_3, c_4)\) that say how many cats of each weight Zenyk gets. If there is a quadruple with \(1 \cdot c_1 + 2 \cdot c_2 + 3 \cdot c_3 + 4 \cdot c_4 = \frac{s}{2}\), the cats can be divided; otherwise they cannot (here \(s\) is the total weight of all cats).
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|