A13076 | New Year Parties
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$ -th friend lives in a house with an integer coordinate $x_i$ . The $i$ -th friend can come celebrate the New Year to the house with coordinate $x_i-1$ , $x_i+1$ or stay at $x_i$ . Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$ , respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$ . The final ones then can be $[1, 3, 3, 4]$ , $[0, 2, 3, 3]$ , $[2, 2, 5, 5]$ , $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
$n$ friends live in a city which can be represented as a number line. The $i$ -th friend lives in a house with an integer coordinate $x_i$ . The $i$ -th friend can come celebrate the New Year to the house with coordinate $x_i-1$ , $x_i+1$ or stay at $x_i$ . Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$ , respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$ . The final ones then can be $[1, 3, 3, 4]$ , $[0, 2, 3, 3]$ , $[2, 2, 5, 5]$ , $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ( $1 \le x_i \le n$ ) — the coordinates of the houses of the friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ( $1 \le x_i \le n$ ) — the coordinates of the houses of the friends.
输出格式
Print two integers — the minimum and the maximum possible number of occupied houses after all moves are performed.
输入输出样例
输入 #1
4 1 2 4 4
输出 #1
2 4
输入 #2
9 1 1 8 8 8 4 4 4 4
输出 #2
3 8
输入 #3
7 4 3 7 1 4 3 3
输出 #3
3 6
In the first example friends can go to $[2, 2, 3, 3]$ . So friend $1$ goes to $x_1+1$ , friend $2$ stays at his house $x_2$ , friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$ . $[1, 1, 3, 3]$ , $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$ , for example.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$ , for example.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted