欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1624A.Plus One on the Subset
Plus One on the Subset
Polycarp got an array of integers as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become ).
- In one operation, he can take some indices in the array and increase the elements of the array at those indices by .
For example, let . He can perform the following operation: select indices 1, 2, and 4 and increase elements of the array in those indices by . As a result, in one operation, he can get a new state of the array .
What is the minimum number of operations it can take so that all elements of the array become equal to each other (that is, to become )?
Input
The first line of the input contains a single integer () — the number of test cases in the test.
The following are descriptions of the input test cases.
The first line of the description of each test case contains one integer () — the array .
The second line of the description of each test case contains integers () — elements of the array .
Output
For each test case, print one integer — the minimum number of operations to make all elements of the array equal.
Note
First test case:
- take and perform an operation plus one on them, as a result we get .
- we take and perform an operation on them plus one, as a result we get .
- we take and perform an operation on them plus one, as a result we get .
There are other sequences of operations, after the application of which all elements become equal.
Second test case:
- 2 times we take and perform an operation plus one on them, as a result we get .
- also take 2 times and perform an operation plus one on it, as a result we get .
Third test case:
- take and perform an operation plus one on it, as a result we get .
Samples
3
6
3 4 2 4 1 2
3
1000 1002 998
2
12 11
3
4
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |