Codeforces Round 523 (Div. 2)
B
Views Matter
Codeforces
1400
原题
← AC →
翻译中…

You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface.

翻译中…

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

翻译中…

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.

翻译中…

image

翻译中…

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 $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 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.

翻译中…

Note

翻译中…

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

翻译中…

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

翻译中…

image

翻译中…

样例

Input #1
5 6
3 3 3 3 3
Output #1
10
InputCopy OutputCopy
Input #2
3 5
1 2 4
Output #2
3
InputCopy OutputCopy
Input #3
5 5
2 3 1 4 4
Output #3
9
InputCopy OutputCopy
Input #4
1 1000
548
Output #4
0
InputCopy OutputCopy
Input #5
3 3
3 1 1
Output #5
1
InputCopy OutputCopy
题目信息
题号
1061B
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。