309574: CF1701C. Schedule Management

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Schedule Management

题意翻译

## 题意简述 有 $n$ 个工人和 $m$ 个任务,每个任务都有且仅有一个工人擅长做,如果让擅长做的工人去做,那么要花一个单位时间,否则要花两个单位时间。请问完成所有的任务至少要花多少时间。 注意:每项工作只能由一个工人完成,不能合作完成。 ## 输入格式 本题多测,对于每组数据,第一行两个整数 $n$ 和 $m$。第二行 $m$ 个数,表示每项工作所擅长的工人编号。 ## 输出格式 每组数据一个整数表示最少要花的时间。

题目描述

There are $ n $ workers and $ m $ tasks. The workers are numbered from $ 1 $ to $ n $ . Each task $ i $ has a value $ a_i $ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $ 1 $ hour. Otherwise, it takes them $ 2 $ hours. The workers work in parallel, independently of each other. Each worker can only work on one task at once. Assign the workers to all tasks in such a way that the tasks are completed as early as possible. The work starts at time $ 0 $ . What's the minimum time all tasks can be completed by?

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of testcases. The first line of each testcase contains two integers $ n $ and $ m $ ( $ 1 \le n \le m \le 2 \cdot 10^5 $ ) — the number of workers and the number of tasks. The second line contains $ m $ integers $ a_1, a_2, \dots, a_m $ ( $ 1 \le a_i \le n $ ) — the index of the worker proficient in the $ i $ -th task. The sum of $ m $ over all testcases doesn't exceed $ 2 \cdot 10^5 $ .

输出格式


For each testcase, print a single integer — the minimum time all tasks can be completed by.

输入输出样例

输入样例 #1

4
2 4
1 2 1 2
2 4
1 1 1 1
5 5
5 1 3 2 4
1 1
1

输出样例 #1

2
3
1
1

说明

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.

Input

题意翻译

## 题意简述 有 $n$ 个工人和 $m$ 个任务,每个任务都有且仅有一个工人擅长做,如果让擅长做的工人去做,那么要花一个单位时间,否则要花两个单位时间。请问完成所有的任务至少要花多少时间。 注意:每项工作只能由一个工人完成,不能合作完成。 ## 输入格式 本题多测,对于每组数据,第一行两个整数 $n$ 和 $m$。第二行 $m$ 个数,表示每项工作所擅长的工人编号。 ## 输出格式 每组数据一个整数表示最少要花的时间。

Output

**题意简述**

有 $n$ 个工人和 $m$ 个任务,每个任务都有且仅有一个工人擅长做,如果让擅长做的工人去做,那么要花一个单位时间,否则要花两个单位时间。请问完成所有的任务至少要花多少时间。

注意:每项工作只能由一个工人完成,不能合作完成。

**输入格式**

本题多测,对于每组数据,第一行两个整数 $n$ 和 $m$。第二行 $m$ 个数,表示每项工作所擅长的工人编号。

**输出格式**

每组数据一个整数表示最少要花的时间。

---

**题目描述**

有 $ n $ 个工人和 $ m $ 个任务。工人的编号从 $ 1 $ 到 $ n $。每个任务 $ i $ 有一个值 $ a_i $ —— 表示擅长这个任务的工人的索引。

每个任务都应该分配一个工人。如果工人擅长这个任务,他们将在 $ 1 $ 小时内完成它。否则,他们将需要 $ 2 $ 小时。

工人们并行工作,相互独立。每个工人一次只能做一个任务。

以尽可能早的方式分配工人到所有任务。工作从时间 $ 0 $ 开始。所有任务能完成的最少时间是多少?

**输入输出格式**

**输入格式**

第一行包含一个整数 $ t $ ($ 1 \le t \le 10^4 $) —— 测试用例的数量。

每个测试用例的第一行包含两个整数 $ n $ 和 $ m $ ($ 1 \le n \le m \le 2 \cdot 10^5 $) —— 工人的数量和任务的数量。

第二行包含 $ m $ 个整数 $ a_1, a_2, \dots, a_m $ ($ 1 \le a_i \le n $) —— 第 $ i $ 个任务擅长的工人的索引。

所有测试用例的 $ m $ 之和不超过 $ 2 \cdot 10^5 $。

**输出格式**

对于每个测试用例,打印一个整数 —— 所有任务能完成的最少时间。

**输入输出样例**

**输入样例 #1**

```
4
2 4
1 2 1 2
2 4
1 1 1 1
5 5
5 1 3 2 4
1 1
1
```

**输出样例 #1**

```
2
3
1
1
```

**说明**

在第一个测试用例中,第一个工人做任务 $ 1 $ 和 $ 3 $,第二个工人做任务 $ 2 $ 和 $ 4 $。因为他们都擅长对应的任务,所以每个任务花费 $ 1 $ 小时。两个工人都完成了 $ 2 $ 个任务,总共花费了 $ 2 $ 小时。因此,所有任务在 $ 2 $ 小时内完成。

在第二个测试用例中,最优的方式是将第一个工人分配给任务 $ 1, 2 $ 和 $ 3 $,将第二个工人分配给任务 $ 4 $。第一个工人花费 $ 3 $ 小时,第二个工人花费 $ 2 $ 小时(因为他们不擅长所接受的任务)。

在第三个例子中,每个工人都可以被分配到他们擅长的任务。因此,他们每个都在 $ 1 $ 小时内完成了任务。**题意简述** 有 $n$ 个工人和 $m$ 个任务,每个任务都有且仅有一个工人擅长做,如果让擅长做的工人去做,那么要花一个单位时间,否则要花两个单位时间。请问完成所有的任务至少要花多少时间。 注意:每项工作只能由一个工人完成,不能合作完成。 **输入格式** 本题多测,对于每组数据,第一行两个整数 $n$ 和 $m$。第二行 $m$ 个数,表示每项工作所擅长的工人编号。 **输出格式** 每组数据一个整数表示最少要花的时间。 --- **题目描述** 有 $ n $ 个工人和 $ m $ 个任务。工人的编号从 $ 1 $ 到 $ n $。每个任务 $ i $ 有一个值 $ a_i $ —— 表示擅长这个任务的工人的索引。 每个任务都应该分配一个工人。如果工人擅长这个任务,他们将在 $ 1 $ 小时内完成它。否则,他们将需要 $ 2 $ 小时。 工人们并行工作,相互独立。每个工人一次只能做一个任务。 以尽可能早的方式分配工人到所有任务。工作从时间 $ 0 $ 开始。所有任务能完成的最少时间是多少? **输入输出格式** **输入格式** 第一行包含一个整数 $ t $ ($ 1 \le t \le 10^4 $) —— 测试用例的数量。 每个测试用例的第一行包含两个整数 $ n $ 和 $ m $ ($ 1 \le n \le m \le 2 \cdot 10^5 $) —— 工人的数量和任务的数量。 第二行包含 $ m $ 个整数 $ a_1, a_2, \dots, a_m $ ($ 1 \le a_i \le n $) —— 第 $ i $ 个任务擅长的工人的索引。 所有测试用例的 $ m $ 之和不超过 $ 2 \cdot 10^5 $。 **输出格式** 对于每个测试用例,打印一个整数 —— 所有任务能完成的最少时间。 **输入输出样例** **输入样例 #1** ``` 4 2 4 1 2 1 2 2 4 1 1 1 1 5 5 5 1 3 2 4 1 1 1 ``` **输出样例 #1** ``` 2 3 1 1 ``` **说明** 在第一个测试用例中,第一个工人做任务 $ 1 $ 和 $ 3 $,第二个工人做任务 $ 2 $ 和 $ 4 $。因为他们都擅长对应的任务,所以每个任务花费 $ 1 $ 小时。两个工人都完成了 $ 2 $ 个任务,总共花费了 $ 2 $ 小时。因此,所有任务在 $ 2 $ 小时内完成。 在第二个测试用例中,最优的方式是将第一个工人分配给任务 $ 1, 2 $ 和 $ 3 $,将第二个工人分配给任务 $ 4 $。第一个工人花费 $ 3 $ 小时,第二个工人花费 $ 2 $ 小时(因为他们不擅长所接受的任务)。 在第三个例子中,每个工人都可以被分配到他们擅长的任务。因此,他们每个都在 $ 1 $ 小时内完成了任务。

加入题单

算法标签: