题目链接

https://vjudge.net/problem/CodeForces-1061B

题面

Description

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 aiai blocks 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 n and mm (1≤n≤100000, 1≤m≤\(10^9\)) — the number of stacks and the height of the exhibit.

The second line contains n integers a1,a2,…,an (1≤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

5 6
3 3 3 3 3

Output

10

Input

3 5
1 2 4

Output

3

Input

5 5
2 3 1 4 4

Output

9

Input

1 1000
548

Output

0

Input

3 3
3 1 1

Output

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.

题意

给定n组木块,每组有a[i]个木块,问可以取走多少块木块使这几组木块的右视图和俯视图不变,拿走木块后其他木块不会因为重力下落

题解

我们可以先排序,然后就直接贪心的选取即可,一开始从最底下的一块开始选,如果当前可以向上走那就向上走(即走斜线选取),不能的话就可以只保留一块木块其他的全拿走,对于最后一组,判断一下之前最高走到多高,如果最后一组的高度大于之前走到高度,那么最后一组就至少要保留这个高度之上的木块,否则保留一块即可

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100050
using namespace std;
int n, m;
int a[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort (a + 1, a + n + 1);
if (n == 1) {
cout << 0;
return 0;
}
int now = 1;
long long ans = a[1] - now;
for (int i = 2; i < n; i++) {
if (a[i] > now) {
now++;
ans += a[i] - 1;
}
else {
ans += a[i] - 1;
}
}
if (a[n] > now) ans += now;
else {
ans += a[n] - 1;
}
cout << ans;
return 0;
}

CodeForces-1061B Views Matter的更多相关文章

  1. Codeforces Round #523 (Div. 2) B Views Matter

    传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 这是一道贪心题么???? 题意: 某展览馆展览一个物品,此物品有n堆,第 i 堆有a[ ...

  2. B. Views Matter

    链接 [http://codeforces.com/contest/1061/problem/B] 题意 问你最多去掉多少块使得从上和右看,投影图不变 分析 注意细节,尤其第一列 代码 #includ ...

  3. 【贪心】【CF1061B】 Views Matter

    Description 给定一个只有一行的,由 \(n\) 组小正方体组成的方块,每组是由 \(a_i\) 块小正方体竖直堆叠起来的,求最多能抽掉多少块使得它的左视图和俯视图不变.方块不会掉落 Inp ...

  4. CF1061B Views Matter

    思路: 贪心. 实现: #include <bits/stdc++.h> using namespace std; ]; int main() { int n, m; while (cin ...

  5. Codeforces Round #523 (Div. 2)

    Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思 ...

  6. Codeforces Round #523 (Div. 2) Solution

    A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (sc ...

  7. Codeforces 528D Fuzzy Search(FFT)

    题目 Source http://codeforces.com/problemset/problem/528/D Description Leonid works for a small and pr ...

  8. Codeforces Round #313 (Div. 2)B.B. Gerald is into Art

    B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/ ...

  9. CodeForces 445B DZY Loves Chemistry

    DZY Loves Chemistry Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Codeforces Round #347 (Div.2)_B. Rebus

    题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...

  2. vuejs父子组件的数据传递

    在vue中,父组件往子组件传递参数都是通过属性的形式来传递的 <div id='root'> <counter :count = '1'></counter> &l ...

  3. office2010激活

    软件下载链接: http://yunpan.cn/cySGrE99u6uv3 (提取码:c612) 下面是操作演示,我录制成gif文件了,下载下来用浏览器打开 360网盘:http://yunpan. ...

  4. CUDA三维数组

    http://hpcbbs.it168.com/forum.php?mod=viewthread&tid=1643 根据上面链接的帖子研究了下三维数组,就像他自己说的一样是有问题的,我自己修改 ...

  5. C# while语句

    一.C# while语句 while语句是用于重复执行程序代码的语句. 语法格式如下: while(boolean-expression){    embedded-statement} 当boole ...

  6. 2.Netty的粘包、拆包(一)

    Netty粘包.拆包 1.什么是拆包.粘包 (1)拆包.粘包介绍 TCP是个"流"协议,所谓流,就是没有界限的一串数据.大家可以想想河里的流水,是连成一片的,其间并没有分界线.TC ...

  7. mysql基础 反范式化

  8. JAVAOOP接口

    狭义接口:用来约束实现类中方法的长相的. 广义接口:已将编写好的功能. 1.接口中的方法都是抽象方法,没有方法体,必须被子类重写 2.java的接口变量都是静态常量 3.接口方法只不过是用来约束现实类 ...

  9. JDK学习---深入理解java中的LinkedList

    本文参考资料: 1.<大话数据结构> 2.http://blog.csdn.net/jzhf2012/article/details/8540543 3.http://blog.csdn. ...

  10. 数据库中where与having的区别

    从整体声明角度分析: “where”是一个约束声明,在查询数据库结果返回之前对数据库的查询条件做一个约束,即返回结果之前起作用,“where”后面不能跟聚合函数: “having”是一个过滤声明,在查 ...