아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Natives

면접 대비

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

요약
값이 정해진 보물 n개 중 절반 이상을 넘겨줄 때 남길 수 있는 가치의 합의 최댓값을 구한다.
난이도

보통10점 중 4점

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

문제

Captain Cook and his team were captured by island natives. Not to be eaten, the adventurers must give some treasures to natives. It turned out that the captain has nn treasures.

Chieftain of the natives agrees to let the captain and his team go, if they give him at least half of his treasures. All treasures look pretty to him, so the chieftain agrees to get any treasures, he only wants to get at least half of them.

But actually each treasure has its own value known to Cook. The value of the ii-th treasure is a_ia\_i. Help the captain to decide which treasures he should give to the chieftain so that the total value of the treasures he keeps to himself is maximum possible.

입력

The first line of input contains integer nn (2≤n≤10002 \le n \le 1000).

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤10001 \le a\_i \le 1000).

출력

Output one integer --- the maximum possible total value of treasures that the captain can keep for himself after he gives at least half of his treasures to the natives.

예제1

  1. 예제 1

    입력
    6
    2 4 1 3 3 5
    
    예상 출력
    12