cf round #523 B

ToDo_2.1.rar 立即下载

B. Views Matter

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

个人比较讨厌模拟,但是签到还是要做,WA了一发之后,发现里面有玄机,不仅每一层要和之前比较,而且还要考虑有可以替换导致影响低层的情况,比较烦。

我用一个lack记录哪一列需要多余的块来补,哪一列有多出来的可以补给后面高的层。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;

ll a[N];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1);
    ll ans = 0;
    a[0] = 0;
    int now = 1;
    
    ll lack = 0, exceed = 0;

    while (now <= n)
    {
        int cnt = 1;
        while (now + 1 <=  n && a[now + 1] == a[now])
            now++, cnt++;
        ll tmp = max(cnt * 1ll, a[now] - a[now - cnt]);
        if (a[now] - a[now - cnt] > cnt)
        {
            exceed += a[now] - a[now - cnt] - cnt;
        }
        else
        {
            lack += cnt - a[now] + a[now - cnt];
            if (exceed >= lack)
            {
                tmp -= lack;
                exceed -= lack;
                lack = 0;
            }
            else
            {
                tmp -= exceed;
                lack = 0;
                exceed = 0;
            }
        }
        ans += a[now] * cnt - tmp;
        //printf("%d %d %lld\n", now, cnt, ans);
        now++;
    }
    printf("%lld\n", ans);
    return 0;
}

 

超声波熔接结构设计.pdf 技术分享 立即下载

相关推荐

电力系统直流潮流计算研究【IEEE9节点】(Matlab代码实现)

内容概要:本文围绕《电力系统直流潮流计算研究【IEEE9节点】(Matlab代码实现)》展开,系统介绍了基于IEEE9标准测试系统的直流潮流计算方法及其Matlab编程实现过程。资源内容聚焦于电力系统稳态分析中的核心问题,详细阐述了直流潮流的数学模型构建、节点导纳矩阵形成、功率注入处理及线性方程组求解等关键技术环节,并提供完整的可运行Matlab代码,便于读者理解与复现。该研究不仅适用于电力系统规划、运行与控制的教学实践,还可作为复杂电网分析的前期基础工具,服务于故障分析、网络重构与优化调度等高级应用场景。该资源隶属于涵盖智能优化算法、机器学习、电力系统管理等多个方向的综合性科研资料体系,具有较高的工程参考价值和教学实用性。; 适合人群:具备电力系统分析基础知识及一定Matlab编程能力的高校电气工程及相关专业的本科生、研究生、科研人员,以及从事电力系统仿真、电网调度与自动化领域的工程技术人员。; 使用场景及目标:①深入理解直流潮流计算的基本原理及其在电力系统分析中的作用;②利用IEEE9节点系统开展教学实验、课程设计或科研验证,掌握潮流计算的数值实现方法;③作为电力系统高级应用(如最优潮流、可靠性评估、分布式电源接入分析)的前置模块进行扩展研究。; 阅读建议:建议读者结合经典电力系统分析教材同步学习,重点理解潮流计算的数学建模思路与Matlab代码的实现逻辑,通过实际运行、调试程序加深对算法流程的理解,并尝试将该方法迁移至其他IEEE标准测试系统(如IEEE14、IEEE30等)进行对比分析,以提升综合应用能力。

CodeForces Round#523(div2)B-Views Matter (模拟水题)

原题链接: http://codeforces.com/contest/1061/problem/B B. Views Matter time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You came to the exhibition ...

wjl_zyl_1314的博客 468

微信收款音箱4G版F5使用说明书

微信收款音箱4G版F5使用说明书

Codeforces Round #523 (Div. 2)

Codeforces Round #523 (Div. 2) Coins                    You have unlimited number of coins with values 1,2,…,n1,2,…,n . You want to select some set of coins having the total value of SS . ...

Z_sea的博客 350

Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包

联网情况下在命令终端CMD中输入“pip install numpy”即可自动安装,pandas和matplotlib同理一样方法进行自动安装。 工作的电脑不能上外网,所以不能通过直接输入pip命令来安装。 环境:电脑上已经安装了Python(没有安装的请参考其他教程)。 Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包的步骤如下: ...

dayou7738的博客 4948

实战指南 | Adjust 与 Facebook、Google Ads 自归因配置全流程解析

本文详细解析了Adjust与Facebook、Google Ads自归因配置的全流程,帮助移动应用出海推广者解决广告归因难题。通过自归因功能(SAN),开发者可以获取更准确的数据、简化配置流程并扩大安装来源覆盖,显著提升广告效果监测和ROI计算效率。

weixin_42528780的博客 542

浪在ACM第七次训练纯C题解

看着网上清一色的C++。。。无奈还没学C++的我只能自己想办法了。。。 A Coins You have unlimited number of coins with values 1,2,…,n1,2,…,n. You want to select some set of coins having the total value of SS. It is allowed to have mult...

一个正在努力的小菜鸡的记录 536

不用标注数据!用SAM 3零成本搞定遥感图像分割:SegEarth-OV3保姆级上手教程

本文介绍了如何利用SAM 3和SegEarth-OV3实现零标注遥感图像分割,提供从环境配置到结果优化的完整教程。通过开放词汇语义分割技术,用户无需标注数据即可快速获得专业级分割结果,适用于光伏板统计、灾害评估等场景。

weixin_30415113的博客 594

1061_B B. Views Matter

B. Views Mattertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou came to the exhibition and one exhibit has drawn your attention. It consists of...

weixin_40488730的博客 237

ML307A模组连接ONENET平台(AT指令步骤教程)

ML307A 是一款集成度高、体积小的物联网通信模组,支持多种无线通信协议,如 LoRa、NB-IoT 等。它具有低功耗、远程通信等特点,适用于多种物联网场景。支持 LoRa 和 NB-IoT 等多种无线通信标准。提供丰富的 GPIO 接口。内置多种传感器支持。UART 接口:用于与微控制器或其他设备通信。GPIO 接口:可以连接外部传感器或执行器。电源接口:用于供电。OneNET 是中国移动推出的一款物联网开放平台,它提供了从数据采集、存储到分析的一站式解决方案。

xiewengeng的博客 5492

软件项目质量管理

识别项目中涉及质量管理的不同角色,如项目经理、质量经理、测试人员等,明确每个角色的职责和任务,包括负责哪些质量管理活动和决策。1、编制软件项目的质量管理计划,包括确定项目的质量标准和要求,以及制定质量控制和质量保证策略等。2、编制软件项目的质量管理计划,包括确定项目的质量标准和要求,以及制定质量控制和质量保证策略等。测试用例表是质量控制过程中的关键工具,确保所有功能和场景都被验证,减少项目中的缺陷。1、理解项目质量管理的基本过程,包括质量计划、质量保证、质量控制和质量改进;明确质量管理活动中的角色和职责。

weixin_51996255的博客 1264

浪在ACM 集训队第七次测试赛

浪在ACM 集训队第七次测试赛A. CoinsInputOutput解析B.Views MatterInputOutput解析C.Vasya and BookInputOutput解析D.Vova and TrophiesInputOutput解析 A. Coins CodeForces 1061A. Coins   You have unlimited number of coins with ...

rp++ 761

北斗导航 | 2023 PTTI会议论文 2023 ITM会议论文 2022 ION GNSS+ 会议论文下载:ION 美国导航学会

2023 国际技术会议(ITM) 2023 精密时间和时间间隔系统和应用会议(PTTI) 2022 美国导航学会国际会议(ION GNSS +)

尘世冰封的专栏 4625

【Codeforces】Round #523 (Div. 2) A-F

CF523Div2

远行客 594

基于 STM32 的智能冰箱食材管理与过期提醒系统设计

define MAX_FOOD 20 // 最多存储20种食材#define EXPIRE_WARN 3 // 剩余≤3天触发提醒// RFID卡号4字节// 食材名称// 保质期(天)// 入库日期// 0=空槽,1=有效。

weixin_42300449的博客 63

Hermes 教程 05:多 Agent 编排

本文介绍了Hermes v0.13.0中的四种多Agent协作模式:1)delegate_task快速子任务模式,适合2-3个独立并行任务;2)spawn子Agent模式,实现零成本并行多步流水线;3)tmux交互子Agent模式,支持长期自主任务;4)全新Kanban看板系统,提供持久化AI团队协作框架。各模式在隔离级别、时长、工具访问和适用场景上存在差异,其中spawn模式通过独立上下文窗口实现零上下文成本。文章详细说明了每种模式的使用方法、限制条件和典型应用场景,并提供了具体代码示例和可视化流程图。K

程序猿_三产 546

cf round #523 C

C. Multiplicity time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given an integer array a1,a2,…,ana1,a2,…,an. The array b...

Pleaseinput的博客 589

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

CF Round #523 (Div. 2)

ACM题集:https://blog.csdn.net/weixin_39778570/article/details/83187443 题目链接:https://codeforces.com/contest/1061 官方题解:https://codeforces.com/blog/entry/63384 A题 题意:1,2,3,4,…n每个数都有无限个,问数k最少能由1~n中几个数组成 #in...

越看越喜欢啊 1710

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #523 (Div. 2) C. Multiplicity

output standard output You are given an integer array a1,a2,…,ana1,a2,…,an. The array bb is called to be a subsequence of aa if it is possible to remove some elements from aa to get bb. Array b1,b...

wxl7777的博客 344

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

传送门 题意:有一堆块,第i块的高度是ai,有一个从上面看到的俯视图,有一个从右面看到的侧视图,现在问从原来的堆中至多取出多少个块保持俯视图和侧视图不变,有两个规定是这样的,第一个就是物块不受重力影响,就是说从下面掏出块上面的不会掉落的意思,第二个是不能用手移动块。 题解:贪心,从大到小排序,然后从开头往后贪,记录一个此时高度为堆的开始,如果一开始高度就为1,那么直接可以算出全部都要留下,如果...

肘子的博客 785

Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)

cf472.d2/* A: 题意:有三种类型的字符C,Y,M,现在给你一串含有C,Y,M,?的字符串, 在?处填上C或Y或M,使得相邻的字符不相同,如果填的方式大于等 于2,输出Yes,否则输出No; 思路:如果含有两个或两个以上的连续问号则必定有两种以上的填法 如果只有一个问号,这个问号在第一位或者最后一位也有两种填法, 或者这个问号的两边的字母相同时,也有两种填法;即只有一个?并 且?两边的...

whiskey_wei的博客 228

比赛

比赛 CF CF Round #520 (Div. 2) CF Round #521 (Div. 3) CF Round #522 (Div. 2) CF Round #523 (Div. 2) CF Round #524 (Div. 2) CF Round #531 (Div. 3) Educational Round 58 (Rated for Div. 2) CF Round #532 ...

越看越喜欢啊 1770

iSCSI 搭好扩容真香,多路径配置翻车能熬通宵

很多运维分不清 iSCSI 与 NFS:NFS 属于文件共享,而 iSCSI 提供远程块设备,客户端识别成一块全新裸硬盘。 本文完整覆盖 iSCSI 服务全流程:从 iSCSI 基础架构、Target 服务部署,backstore、IQN、LUN、ACL、Portal 全套配置;讲解客户端发现、连接、格式化、持久化挂载;重点讲解 multipath 多路径访问,实现链路冗余高可用,附带故障处理、高可用测试与配置文件详解。 适合需要搭建网络块存储、服务器扩容、构建存储冗余链路的运维工程师阅读。

cyw_lesson的博客 292

Codeforces Round #523 (Div. 2) B,D

B 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 ai blocks resting on the surface. The height of the exhibi...

qq_42133677的博客 238

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

B. Views Matter time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You came to the exhibition and one exhibit has drawn your attenti...

pxlsdz的博客 515
上一篇: codeforces Round #523  A. Coins
下一篇: cf round #523 C
「已注销」
博客等级 码龄9年 6粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值