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

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

Finding Forks

면접 대비

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

요약
여러 종류의 포크 개수가 주어질 때, 최소 두 칸이 비게 되는 최소 세척 포크 수를 구한다.
난이도

보통10점 중 4점

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

문제

Your cutlery drawer contains many types of forks. Each with their own purpose, and each with its own place in the cutlery drawer. After a nice dining party with all your friends, disaster struck! You put all the used forks in the dishwasher, but now you are unsure where to put back some of the forks, because at least two places in the cutlery drawer are empty! And worse, you do not remember which type of fork belongs where!

What is the minimum number of forks that must have been in the dishwasher to cause this confusion?

입력

The input consists of:

  • One line with an integer nn (2≤n≤1052\leq n\leq 10^5), the number of types of forks.
  • One line with nn integers aa (1≤a≤1091\leq a \leq 10^9), the number of forks of each type.

출력

Output the minimum number of forks that must have been in the dishwasher.

예제2

  1. 예제 1

    입력
    3
    4 9 5
    
    예상 출력
    9
    
  2. 예제 2

    입력
    10
    18 39 5 12 1000000000 54 23 11 123 31415
    
    예상 출력
    16