310112: CF1784A. Monsters (easy version)
Memory Limit:512 MB
Time Limit:4 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Monsters (easy version)
题意翻译
#### 题目描述 你正在打游戏。 现在有 $n$ 只怪物,第 $i$ 只有 $a_i$ 点血。 你当然要把它们打死。你有两种攻击方式: 1. 选取任意一只怪物,扣除它 $1$ 点血。这种攻击方式可以无限次使用。 2. 使所有怪物各扣除 $1$ 点血,如果有怪物被这次攻击「杀死」了,就立即再进行一次这种攻击。**注意,这种攻击方式每局只能用一次。** 其中,「杀死」一只怪物需要让它的血量小于等于 $0$。被「杀死」的怪物立即退出游戏。 你要求出「杀死」所有怪物使用攻击方式 1 的最小次数。 **本题有多组数据。** 第一行,一个整数 $t(t\leq10^4)$,代表数据组数。 每组数据包含两行。第一行,一个整数 $n$,代表怪物数。第二行,$n$ 个整数 $a_i$,代表每只怪物的血量。 保证 $1\leq n\leq2\cdot10^5,\sum n\leq 2\cdot10^5,1\leq a_i\leq n$。题目描述
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 $ n $ monsters. Monster number $ i $ has $ a_i $ health points, all $ a_i $ are integers. A monster is alive while it has at least $ 1 $ health point. You can cast spells of two types: 1. Deal $ 1 $ damage to any single alive monster of your choice. 2. Deal $ 1 $ damage to all alive monsters. If at least one monster dies (ends up with $ 0 $ health points) as a result of this action, then repeat it (and keep repeating while at least one monster dies every time). Dealing $ 1 $ damage to a monster reduces its health by $ 1 $ . 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?输入输出格式
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows. Each test case consists of two lines. The first line contains a single integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of monsters. The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ) — monsters' health points. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
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.
输入输出样例
输入样例 #1
2
3
3 1 2
6
4 1 5 4 1 1
输出样例 #1
0
4