Karamell

면접 대비

시간 제한1초메모리 제한1024 MB

요약
주어진 N개의 봉지 크기를 어떤 순서로 분배해야 가장 적게 가진 사람에게 주는 규칙 아래에서 앨리스와 밥이 같은 양을 받게 되는지 그 순서를 찾는다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 구현, 수학
정답자
아직 제출이 없습니다

문제

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: NN bags of caramels. The ii-th bag contained a_ia\_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 ii-th step, the a_ia\_i caramels from the ii-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]\[1, 2, 2, 3], Alice would end up with 33 and Bob would end up with 55 candies. On the other hand, if they were considered in the order \[1,2,3,2]\[1, 2, 3, 2], both would end up with 44.

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 NN (1≤N≤1001 ≤ N ≤ 100), indicating the number of bags. The second line contains NN integers a_1,…,a_Na\_1, \dots , a\_N (1≤a_i≤1001 ≤ a\_i ≤ 100), where a_ia\_i indicates the number of candies in bag ii.

출력

The output must be a single line. If it is impossible to find an order as requested, print -1. Otherwise, print NN integers separated by spaces, indicating a valid ordering of the a_ia\_i values that guarantees that the candies will be divided equally among the siblings.

예제3

  1. 예제 1

    입력
    4
    1 2 2 3
    
    예상 출력
    1 2 3 2
    
  2. 예제 2

    입력
    5
    1 2 2 3 6
    
    예상 출력
    3 6 2 2 1
    
  3. 예제 3

    입력
    6
    1 12 21 23 33 34
    
    예상 출력
    -1