| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 53 | 24 | 22 | 51.163% |
Karamell, Caramel, Caramello or Caramelo. Different languages, but you know what I’m talking about. Alice and Bob are twins and they also love caramels! So, as a birthday present, they asked for caramels to all the guests at the party they are organizing.
The day of the party Alice and Bob received their presents: $N$ bags of caramels. The $i$-th bag contained $a_i$ caramels.
Alice and Bob don’t want to open the bags right away, they decided to distribute the caramels in the following way: the bags will be considered in order and, at the $i$-th step, the $a_i$ caramels from the $i$-th bag are given to the person who has the least caramels at that moment. In case of a tie, Alice gets the caramels (after all, “ladies first”).
One thing they didn’t like is that, depending on the order in which the bags are considered, the final amount of caramels that each person receives can be different. For example, if the bags were ordered in the quantities described by the sequence $[1, 2, 2, 3],ドル Alice would end up with 3ドル$ and Bob would end up with 5ドル$ candies. On the other hand, if they were considered in the order $[1, 2, 3, 2],ドル both would end up with 4ドル$.
You forgot to buy candies for the birthday children, but you decided to give them an even more interesting gift: a program that determines a way to order the bags so that Alice and Bob get the same amount of candies, if possible.
The first line contains a single integer $N$ (1ドル ≤ N ≤ 100$), indicating the number of bags. The second line contains $N$ integers $a_1, \dots , a_N$ (1ドル ≤ a_i ≤ 100$), where $a_i$ indicates the number of candies in bag $i$.
The output must be a single line. If it is impossible to find an order as requested, print -1. Otherwise, print $N$ integers separated by spaces, indicating a valid ordering of the $a_i$ values that guarantees that the candies will be divided equally among the siblings.
4 1 2 2 3
1 2 3 2
5 1 2 2 3 6
3 6 2 2 1
6 1 12 21 23 33 34
-1
ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação da SBC 2024 K번