E. New Year Parties

194 篇文章 1 订阅
32 篇文章 0 订阅

链接: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 or 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] or [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);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值