A12987 | Yet Another Division Into Teams
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ students at your university. The programming skill of the $i$ -th student is $a_i$ . As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has $2 \cdot 10^5$ students ready for the finals!
Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of $k$ students with programming skills $a[i_1], a[i_2], \dots, a[i_k]$ , then the diversity of this team is $\max\limits_{j=1}^{k} a[i_j] - \min\limits_{j=1}^{k} a[i_j]$ ).
The total diversity is the sum of diversities of all teams formed.
Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.
Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of $k$ students with programming skills $a[i_1], a[i_2], \dots, a[i_k]$ , then the diversity of this team is $\max\limits_{j=1}^{k} a[i_j] - \min\limits_{j=1}^{k} a[i_j]$ ).
The total diversity is the sum of diversities of all teams formed.
Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.
输入格式
The first line of the input contains one integer $n$ ( $3 \le n \le 2 \cdot 10^5$ ) — the number of students.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the programming skill of the $i$ -th student.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the programming skill of the $i$ -th student.
输出格式
In the first line print two integers $res$ and $k$ — the minimum total diversity of the division of students and the number of teams in your division, correspondingly.
In the second line print $n$ integers $t_1, t_2, \dots, t_n$ ( $1 \le t_i \le k$ ), where $t_i$ is the number of team to which the $i$ -th student belong.
If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.
In the second line print $n$ integers $t_1, t_2, \dots, t_n$ ( $1 \le t_i \le k$ ), where $t_i$ is the number of team to which the $i$ -th student belong.
If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.
输入输出样例
输入 #1
5 1 1 3 4 2
输出 #1
3 1 1 1 1 1 1
输入 #2
6 1 5 12 13 2 15
输出 #2
7 2 2 2 1 1 2 1
输入 #3
10 1 2 5 129 185 581 1041 1909 1580 8150
输出 #3
7486 3 3 3 3 2 2 2 2 1 1 1
In the first example, there is only one team with skills $[1, 1, 2, 3, 4]$ so the answer is $3$ . It can be shown that you cannot achieve a better answer.
In the second example, there are two teams with skills $[1, 2, 5]$ and $[12, 13, 15]$ so the answer is $4 + 3 = 7$ .
In the third example, there are three teams with skills $[1, 2, 5]$ , $[129, 185, 581, 1041]$ and $[1580, 1909, 8150]$ so the answer is $4 + 912 + 6570 = 7486$ .
In the second example, there are two teams with skills $[1, 2, 5]$ and $[12, 13, 15]$ so the answer is $4 + 3 = 7$ .
In the third example, there are three teams with skills $[1, 2, 5]$ , $[129, 185, 581, 1041]$ and $[1580, 1909, 8150]$ so the answer is $4 + 912 + 6570 = 7486$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted