This is the easy version of the problem. In this version, you only need to find the answer once. In this version, hacks are not allowed.
In a computer game, you are fighting against nn monsters. Monster number ii has aiai health points, all aiai are integers. A monster is alive while it has at least 11 health point.
You can cast spells of two types:
- Deal 11 damage to any single alive monster of your choice.
- Deal 11 damage to all alive monsters. If at least one monster dies (ends up with 00 health points) as a result of this action, then repeat it (and keep repeating while at least one monster dies every time).
Dealing 11 damage to a monster reduces its health by 11.
Spells of type 1 can be cast any number of times, while a spell of type 2 can be cast at most once during the game.
What is the smallest number of times you need to cast spells of type 1 to kill all monsters?
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.
Each test case consists of two lines. The first line contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of monsters.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — monsters' health points.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, print a single integer — the smallest number of times you need to cast spells of type 1 to kill all monsters.
Example
input
Copy
2
3
3 1 2
6
4 1 5 4 1 1
output
Copy
0 4
Note
In the first test case, the initial health points of the monsters are [3,1,2][3,1,2]. It is enough to cast a spell of type 2:
- Monsters' health points change to [2,0,1][2,0,1]. Since monster number 22 dies, the spell is repeated.
- Monsters' health points change to [1,0,0][1,0,0]. Since monster number 33 dies, the spell is repeated.
- Monsters' health points change to [0,0,0][0,0,0]. Since monster number 11 dies, the spell is repeated.
- Monsters' health points change to [0,0,0][0,0,0].
Since it is possible to use no spells of type 1 at all, the answer is 00.
In the second test case, the initial health points of the monsters are [4,1,5,4,1,1][4,1,5,4,1,1]. Here is one of the optimal action sequences:
- Using a spell of type 1, deal 11 damage to monster number 11. Monsters' health points change to [3,1,5,4,1,1][3,1,5,4,1,1].
- Using a spell of type 1, deal 11 damage to monster number 44. Monsters' health points change to [3,1,5,3,1,1][3,1,5,3,1,1].
- Using a spell of type 1, deal 11 damage to monster number 44 again. Monsters' health points change to [3,1,5,2,1,1][3,1,5,2,1,1].
- Use a spell of type 2:
- Monsters' health points change to [2,0,4,1,0,0][2,0,4,1,0,0]. Since monsters number 22, 55, and 66 die, the spell is repeated.
- Monsters' health points change to [1,0,3,0,0,0][1,0,3,0,0,0]. Since monster number 44 dies, the spell is repeated.
- Monsters' health points change to [0,0,2,0,0,0][0,0,2,0,0,0]. Since monster number 11 dies, the spell is repeated.
- Monsters' health points change to [0,0,1,0,0,0][0,0,1,0,0,0].
- Using a spell of type 1, deal 11 damage to monster number 33. Monsters' health points change to [0,0,0,0,0,0][0,0,0,0,0,0].
Spells of type 1 are cast 44 times in total. It can be shown that this is the smallest possible number.
这是该问题的简单版本。在这个版本中,你只需要找到一次答案。在这个版本中,不允许有黑客。
在一个电脑游戏中,你要与n个怪物战斗。编号为i的怪物有ai健康点数,所有ai都是整数。当一个怪物至少有1个健康点时,它就是活的。
你可以施展两种类型的法术。
对你选择的任何一个活着的怪物造成1点伤害。
对所有活着的怪物造成1点伤害。如果至少有一只怪物因这一行动而死亡(最终生命值为0),那么就重复这一行动(并且不断重复,每次至少有一只怪物死亡)。
对一个怪物造成1次伤害,使其健康值减少1。
类型1的法术可以施放任意次数,而类型2的法术在游戏中最多可以施放一次。
为了杀死所有的怪物,你需要施放1类法术的最小次数是多少?
输入
每个测试包含多个测试用例。第一行包含测试用例的数量t(1≤t≤104)。测试用例的描述如下。
每个测试用例由两行组成。第一行包含一个整数n(1≤n≤2⋅105)--怪物的数量。
第二行包含n个整数a1,a2,...,an(1≤ai≤n)--怪物的健康点数。
保证所有测试案例的n之和不超过2⋅105。
输出
对于每个测试用例,打印一个整数--你需要施放类型为1的法术杀死所有怪物的最小次数。
由于第二个技能只能使用一次的原因,所以要通过第一个技能调整挂物血量,然后一个二技能全部带走。控制每个怪物血量差1就行
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<map>
#include<cstring>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
ll gcdd(ll a, ll b)
{
if (b) while ((a %= b) && (b %= a));
return a + b;
}
struct node
{
};
int n, w,h;
int arr[N];
ll brr[N];
int main() {
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> arr[i];
}
sort(arr+1, arr+1 + n);
ll ans = 0;
for (int i = 1;i <= n;i++)
{
if (arr[i] - arr[i - 1] > 1)
{
ans += (arr[i] - arr[i - 1] - 1);
arr[i] = arr[i - 1] + 1;
}
}
cout << ans << endl;
}
}