欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2152A.Increase or Smash
Increase or Smash
Geumjae has an array consisting of zeros. His goal is to transform it into a given target array using a minimum number of operations.
He can perform the following two types of operations any number of times, in any order:
- Increase: Choose any positive integer . Increase all elements of the array by . In other words, he chooses a positive integer , and for each (), he replaces with .
- Smash: Set some elements (possibly none or all) of the array to . In other words, for each (), he either replaces with or leaves it as before.
Given the final target state of the array , find the minimum total number of operations (both Increase and Smash) Geumjae needs to perform.
It can be shown that for any given final array, a sequence of operations always exists.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line contains a single integer () — the number of elements in the array .
The second line contains integers () — the elements of the target array .
Output
For each test case, output a single integer — the minimum number of operations required.
Note
Explanation of the first test case:
The target array is . A possible sequence of 3 operations (which is the minimum) is:
- Initially, the array is . After an Increase operation with , the array becomes .
- Next, after a Smash operation on the first two elements, the array becomes .
- Finally, after an Increase operation with , the array becomes .
We used Increase operations and Smash operation for a total of operations.
Explanation of the second test case:
The target array is . A single Increase operation with gives the target array.
Samples
3
3
1 1 3
1
100
9
9 9 3 2 4 4 8 5 3
3
1
11
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |