CF1701C Schedule Management
题目描述
有 $n$ 个工人和 $m$ 个任务,每个任务都有且仅有一个工人擅长做,如果让擅长做的工人去做,那么要花一个单位时间,否则要花两个单位时间。请问完成所有的任务至少要花多少时间。
注意:每项工作只能由一个工人完成,不能合作完成。
输入格式
第一行包含一个整数 $t$($1 \leq t \leq 10^4$),表示测试用例的数量。
对于每个测试用例,第一行包含两个整数 $n$ 和 $m$($1 \leq n \leq m \leq 2 \cdot 10^5$)。第二行 $m$ 个正整数 $a_1, a_2, \ldots, a_m$($1 \leq a_i \leq n$),表示每项工作所擅长的工人编号。
所有测试用例中 $m$ 的总和不超过 $2 \cdot 10^5$。
输出格式
每组数据一个整数表示最少要花的时间。
说明/提示
In the first testcase, the first worker works on tasks $ 1 $ and $ 3 $ , and the second worker works on tasks $ 2 $ and $ 4 $ . Since they both are proficient in the corresponding tasks, they take $ 1 $ hour on each. Both of them complete $ 2 $ tasks in $ 2 $ hours. Thus, all tasks are completed by $ 2 $ hours.
In the second testcase, it's optimal to assign the first worker to tasks $ 1, 2 $ and $ 3 $ and the second worker to task $ 4 $ . The first worker spends $ 3 $ hours, the second worker spends $ 2 $ hours (since they are not proficient in the taken task).
In the third example, each worker can be assigned to the task they are proficient at. Thus, each of them complete their task in $ 1 $ hour.