시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 149 60 56 45.902%

문제

희원이는 그의 다락방에서 N개의 체인을 찾았다. 각각의 체인은 몇 개의 고리로 연결되어 있는데, 각각의 고리는 최대 두 개의 인접한 고리를 가질 수 있다. 각각의 고리는 열고 닫을 수 있다. 그래서, 체인을 분리하거나 두 체인을 연결하여 하나의 긴 체인으로 만들 수 있다. 희원이는 가능한 한 적은 고리를 열고 닫아서, 모든 체인을 하나의 긴 체인으로 연결하려고 한다.

예를 들어, 희원이가 세 개의 체인을 가지고 있고, 각 체인이 고리 하나로만 이루어져 있다면, 그 중 하나를 열어서 나머지 두 개를 연결하고 닫으면 된다.

체인의 개수와 각각의 체인의 길이가 주어지면, 하나의 긴 체인으로 모든 체인을 묶기 위해 희원이가 열고 닫아야할 최소한의 고리 수를 찾아라.

입력

첫번째 줄에는 체인의 개수를 나타내는 양의 정수 N (2 ≤ N ≤ 500000)이 주어진다. 두번째 줄에는 각각의 체인의 길이를 나타내는 N개의 양의 정수 Li(1 ≤ Li ≤ 1000000)가 주어진다.

출력

첫째 줄에 필요한 고리의 최소 개수를 출력한다.

예제 입력 1

5
4 3 5 7 9

예제 출력 1

3
W3sicHJvYmxlbV9pZCI6IjI3ODUiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWNjYjRcdWM3NzgiLCJkZXNjcmlwdGlvbiI6IjxwPlx1ZDc2Y1x1YzZkMFx1Yzc3NFx1YjI5NCBcdWFkZjhcdWM3NTggXHViMmU0XHViNzdkXHViYzI5XHVjNWQwXHVjMTFjIE5cdWFjMWNcdWM3NTggXHVjY2I0XHVjNzc4XHVjNzQ0IFx1Y2MzZVx1YzU1OFx1YjJlNC4gXHVhYzAxXHVhYzAxXHVjNzU4IFx1Y2NiNFx1Yzc3OFx1Yzc0MCBcdWJhODcgXHVhYzFjXHVjNzU4IFx1YWNlMFx1YjlhY1x1Yjg1YyBcdWM1ZjBcdWFjYjBcdWI0MThcdW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G8gb3BlbiBhbmQgY2xvc2UgaW4gb3JkZXIgdG8gYmluZCB0aGVtIGFsbCBpbiBkYXJrbmVzcyBvbmUgbG9uZyBjaGFpbi48XC9wPlxyXG4iLCJpbnB1dCI6IjxwPlRoZSBmaXJzdCBsaW5lIG9mIGlucHV0IGNvbnRhaW5zIHRoZSBwb3NpdGl2ZSBpbnRlZ2VyIE4gKDIgJmxlOyBOICZsZTsgNTAwIDAwMCksIHRoZSBudW1iZXIgb2YgY2hhaW5zLjxcL3A+XHJcblxyXG48cD5UaGUgc2Vjb25kIGxpbmUgb2YgaW5wdXQgY29udGFpbnMgTiBwb3NpdGl2ZSBpbnRlZ2VycyBMPHN1Yj5pPFwvc3ViPiAoMSAmbGU7IEw8c3ViPmk8XC9zdWI+ICZsZTsgMSAwMDAgMDAwKSwgdGhlIGxlbmd0aHMgb2YgaW5kaXZpZHVhbCBjaGFpbnM8XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD5UaGUgZmlyc3QgYW5kIG9ubHkgbGluZSBvZiBvdXRwdXQgbXVzdCBjb250YWluIHRoZSByZXF1aXJlZCBtaW5pbXVtIG51bWJlciBvZiBsaW5rcy48XC9wPlxyXG5cclxuPHA+Jm5ic3A7PFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Contest > Croatian Open Competition in Informatics > COCI 2012/2013 > Contest #2 3번

  • 문제를 번역한 사람: baekjoon
  • 잘못된 번역을 찾은 사람: jh05013