欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2014C.Robin Hood in Town
Robin Hood in Town
In Sherwood, we judge a man not by his wealth, but by his merit.
Look around, the rich are getting richer, and the poor are getting poorer. We need to take from the rich and give to the poor. We need Robin Hood!
There are people living in the town. Just now, the wealth of the -th person was gold. But guess what? The richest person has found an extra pot of gold!
More formally, find an , change to , where is a non-negative integer number of gold found in the pot. If there are multiple maxima, it can be any one of them.
A person is unhappy if their wealth is strictly less than half of the average wealth.
If strictly more than half of the total population are unhappy, Robin Hood will appear by popular demand.
Determine the minimum value of for Robin Hood to appear, or output if it is impossible.
The average wealth is defined as the total wealth divided by the total population , that is, , the result is a real number.
Input
The first line of input contains one integer () — the number of test cases.
The first line of each test case contains an integer () — the total population.
The second line of each test case contains integers () — the wealth of each person.
It is guaranteed that the sum of across all test cases does not exceed .
Output
For each test case, output one integer — the minimum number of gold that the richest person must find for Robin Hood to appear. If it is impossible, output instead.
Note
In the first test case, it is impossible for a single person to be unhappy.
In the second test case, there is always happy person (the richest).
In the third test case, no additional gold are required, so the answer is .
In the fourth test case, after adding gold, the average wealth becomes , and half of this average is , resulting in people being unhappy.
In the fifth test case, after adding gold, the average wealth becomes , resulting in people being unhappy.
Samples
6
1
2
2
2 19
3
1 3 20
4
1 2 3 4
5
1 2 3 4 5
6
1 2 1 1 1 25
-1
-1
0
15
16
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |