CF1283E.New Year Parties
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 xi. The i-th friend can come celebrate the New Year to the house with coordinate xi−1, xi+1 or stay at xi. Each friend is allowed to move no more than once.
For all friends 1≤xi≤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 位朋友住在一座可表示为数轴的城市中。第 i 位朋友住在坐标为整数 xi 的房屋中。第 i 位朋友可以前往坐标为 xi−1、xi+1 的房屋庆祝新年,或者留在原处 xi。每位朋友最多只能移动一次。
对所有朋友均满足 1≤xi≤n,但他们可以前往坐标为 0 或 n+1 的房屋(例如:若某位朋友原本住在坐标 1,则可前往 0;若原本住在 n,则可前往 n+1)。
例如,设初始位置为 x=[1,2,4,4],则最终位置可以是 [1,3,3,4]、[0,2,3,3]、[2,2,5,5]、[2,1,3,5] 等等。被占据的房屋数量即为最终位置中不同坐标的个数。
因此,所有朋友各自独立选择是否移动以及如何移动。随后计算被占据的房屋总数。那么,被占据的房屋数量最小可能值与最大可能值分别是多少?
输入格式
The first line contains a single integer n (1≤n≤2⋅105) — the number of friends.
The second line contains n integers x1,x2,…,xn (1≤xi≤n) — the coordinates of the houses of the friends.
第一行包含一个整数 n(1≤n≤2⋅105)——朋友的数量。
第二行包含 n 个整数 x1,x2,…,xn(1≤xi≤n)——朋友们各自房屋的坐标。
输出格式
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 x1+1, friend 2 stays at his house x2, friend 3 goes to x3−1 and friend 4 goes to x4−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.
在第一个例子中,朋友们可以前往 [2,2,3,3]。因此,朋友 1 前往 x1+1,朋友 2 留在自己家 x2,朋友 3 前往 x3−1,朋友 4 前往 x4−1。[1,1,3,3]、[2,2,3,3] 或 [2,2,4,4] 同样都是能获得 2 个被占据房屋的有效方案。
为使被占据房屋数量最大化,朋友们可前往 [1,2,3,4] 或 [0,2,4,5] 等位置。
输入解题思路,AI测评打分。不知道怎么写?