B. Views Matter

链接:https://codeforces.com/contest/1061/problem/B

You came to the exhibition and one exhibit has drawn your attention. It consists of nn stacks of blocks, where the ii-th stack consists of aiaiblocks resting on the surface.

The height of the exhibit is equal to mm. Consequently, the number of blocks in each stack is less than or equal to mm.

There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.

Find the maximum number of blocks you can remove such that the views for both the cameras would not change.

Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either.

Input

The first line contains two integers nn and mm (1≤n≤1000001≤n≤100000, 1≤m≤1091≤m≤109) — the number of stacks and the height of the exhibit.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤m1≤ai≤m) — the number of blocks in each stack from left to right.

Output

Print exactly one integer — the maximum number of blocks that can be removed.

Examples

input

Copy

5 6
3 3 3 3 3

output

Copy

10

input

Copy

3 5
1 2 4

output

Copy

3

input

Copy

5 5
2 3 1 4 4

output

Copy

9

input

Copy

1 1000
548

output

Copy

0

input

Copy

3 3
3 1 1

output

Copy

1

Note

The following pictures illustrate the first example and its possible solution.

Blue cells indicate removed blocks. There are 1010 blue cells, so the answer is 1010.

代码:

#include <bits/stdc++.h>
using namespace std;
long long t,n,m,k,s=0,max1=0;
long long a[1000001];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	if(n==1)
	cout<<0;
	else
	{
		
		k=1;
		s+=a[1]-1; 
		for(int i=2;i<n;i++)
		{
			if(a[i]>k)
			{
				s+=a[i]-1;
				k++;
			}
			else
			{
				s+=k-1;
			}
		}
		if(a[n]>k)
		s+=k;
		else
		s+=a[n]-1;
		cout<<s;
	}
	
}

 

全部评论

相关推荐

08-15 01:16
Python
Java小萌新新萌小...:照片不用整这么大的 而且你的照片截歪了 你想找专业对口的 那普通话证写在这里其实没有什么必要 就是看着内容多点 而且里面字体大小也不一样 修改一下排版 有很多空间可以再利用一下 字大一点 不然现在这样观感不太好 再就是项目好好优化一下 加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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