E. New Year Parties

链接:https://codeforces.com/contest/1283/problem/E

Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...

nn friends live in a city which can be represented as a number line. The ii-th friend lives in a house with an integer coordinate xixi. The ii-th friend can come celebrate the New Year to the house with coordinate xi−1xi−1, xi+1xi+1 or stay at xixi. Each friend is allowed to move no more than once.

For all friends 1≤xi≤n1≤xi≤n holds, however, they can come to houses with coordinates 00 and n+1n+1 (if their houses are at 11&nbs***bsp;nn, respectively).

For example, let the initial positions be x=[1,2,4,4]x=[1,2,4,4]. The final ones then can be [1,3,3,4][1,3,3,4], [0,2,3,3][0,2,3,3], [2,2,5,5][2,2,5,5], [2,1,3,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?

Input

The first line contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of friends.

The second line contains nn integers x1,x2,…,xnx1,x2,…,xn (1≤xi≤n1≤xi≤n) — the coordinates of the houses of the friends.

Output

Print two integers — the minimum and the maximum possible number of occupied houses after all moves are performed.

Examples

input

Copy

4
1 2 4 4

output

Copy

2 4

input

Copy

9
1 1 8 8 8 4 4 4 4

output

Copy

3 8

input

Copy

7
4 3 7 1 4 3 3

output

Copy

3 6

Note

In the first example friends can go to [2,2,3,3][2,2,3,3]. So friend 11 goes to x1+1x1+1, friend 22 stays at his house x2x2, friend 33 goes to x3−1x3−1 and friend 44 goes to x4−1x4−1. [1,1,3,3][1,1,3,3], [2,2,3,3][2,2,3,3]&nbs***bsp;[2,2,4,4][2,2,4,4] are also all valid options to obtain 22 occupied houses.

For the maximum number of occupied houses friends can go to [1,2,3,4][1,2,3,4] or to [0,2,4,5][0,2,4,5], for example.

代码:

#include <bits/stdc++.h>
using namespace std;
long long t,n,b,k,s=0,sum=0,min1=0,max1=0;
long long a[200005];
map<long long ,int>m,f,g;
int main()
{
    scanf("%lld",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(f[a[i]-1]||f[a[i]]||a[i-1]==a[i]) 
		continue;
		min1++;
		f[a[i]+1]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==a[i-1]) 
		continue;
		for(int j=1;j<=min(3,m[a[i]]);j++)
		{
			if(!g[a[i]-1])
			{
				g[a[i]-1]=1;
				max1++;
			} 
			else if(!g[a[i]]) 
			{
				g[a[i]]=1;
				max1++;
			}
			else if(!g[a[i]+1]) 
			{
				g[a[i]+1]=1;
				max1++;
			}
		}
	}
	printf("%lld %lld",min1,max1);
}

 

全部评论

相关推荐

Vincent777...:实习经历可以考虑放上去,对于软件使用方面可以细化一些,比如调整为:熟悉基于LSDYNA的瞬态动力学仿真分析,熟悉基于WORKBENCH的结构拓扑优化
我的简历长这样
点赞 评论 收藏
分享
给我发了笔试链接,想着等晚上回去做,结果还没做流程就终止了
伟大的小黄鸭在学习:我猜就是笔试几乎没用,就是用来给用人部门拖时间复筛简历的,可能用人部门筛到你简历觉得不合适就提前挂了
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务