A13038 | The Feast and the Bus
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Employees of JebTrains are on their way to celebrate the 256-th day of the year! There are $n$ employees and $k$ teams in JebTrains. Each employee is a member of some (exactly one) team. All teams are numbered from $1$ to $k$ . You are given an array of numbers $t_1, t_2, \dots, t_n$ where $t_i$ is the $i$ -th employee's team number.
JebTrains is going to rent a single bus to get employees to the feast. The bus will take one or more rides. A bus can pick up an entire team or two entire teams. If three or more teams take a ride together they may start a new project which is considered unacceptable. It's prohibited to split a team, so all members of a team should take the same ride.
It is possible to rent a bus of any capacity $s$ . Such a bus can take up to $s$ people on a single ride. The total cost of the rent is equal to $s \cdot r$ burles where $r$ is the number of rides. Note that it's impossible to rent two or more buses.
Help JebTrains to calculate the minimum cost of the rent, required to get all employees to the feast, fulfilling all the conditions above.
JebTrains is going to rent a single bus to get employees to the feast. The bus will take one or more rides. A bus can pick up an entire team or two entire teams. If three or more teams take a ride together they may start a new project which is considered unacceptable. It's prohibited to split a team, so all members of a team should take the same ride.
It is possible to rent a bus of any capacity $s$ . Such a bus can take up to $s$ people on a single ride. The total cost of the rent is equal to $s \cdot r$ burles where $r$ is the number of rides. Note that it's impossible to rent two or more buses.
Help JebTrains to calculate the minimum cost of the rent, required to get all employees to the feast, fulfilling all the conditions above.
输入格式
The first line contains two integers $n$ and $k$ ( $1 \le n \le 5\cdot10^5, 1 \le k \le 8000$ ) — the number of employees and the number of teams in JebTrains. The second line contains a sequence of integers $t_1, t_2, \dots, t_n$ , where $t_i$ ( $1 \le t_i \le k$ ) is the $i$ -th employee's team number. Every team contains at least one employee.
输出格式
Print the minimum cost of the rent.
输入输出样例
输入 #1
6 3 3 1 2 3 2 3
输出 #1
6
输入 #2
10 1 1 1 1 1 1 1 1 1 1 1
输出 #2
10
输入 #3
12 4 1 2 3 1 2 3 4 1 2 1 2 1
输出 #3
12
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted