NOMURA プログラミングコンテスト 2021 (AtCoder Regular Contest 121)
翻译中…
Problem Statement
翻译中…
Snuke has a blackboard and $N$ candies. The tastiness of the $i$-th candy is $a_i$.
翻译中…
He will repeat the operation below until he has no more candy.
翻译中…
- Choose one or two of his candies and eat them (of course, they disappear). Then, write on the blackboard the total tastiness of the candies he has just chosen.
翻译中…
Snuke wants to minimize $X-Y$, where $X$ and $Y$ are the largest and smallest values written on the blackboard, respectively. Find the minimum possible value of $X-Y$.
翻译中…
Constraints
翻译中…
- All values in input are integers.
$1 \leq N \leq 5000$$-10^{9} \leq a_i \leq 10^9$
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
a_{1} a_{2} \cdots a_N
翻译中…
Output
翻译中…
Print the minimum possible value of $X-Y$, where $X$ and $Y$ are the largest and smallest values written on the blackboard, respectively.
翻译中…
样例
Input #1
3
1 2 4
Output #1
1
- One optimal sequence of operations is to eat the candies with the tastinesses of $1$ and $2$ in the first operation, and then eat the candies with the tastiness of $4$ in the second operation.
Input #2
2
-100 -50
Output #2
0
- It is optimal to eat both candies with the tastiness of $-100$ and $-50$ in the first operation.
Input #3
20
-18 31 -16 12 -44 -5 24 17 -37 -31 46 -24 -2 11 32 16 0 -39 35 38
Output #3
13
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。