当前位置:网站首页>Codeforces Round #803 (Div. 2) B. Rising Sand
Codeforces Round #803 (Div. 2) B. Rising Sand
2022-07-15 19:32:00 【追烽】
https://codeforces.com/contest/1698/problem/B
标签
数组操作
题意
给定长度为 n 的数组 a. 对于 1 < i < n, 如果 a[i] > a[i - 1] + a[i + 1], 定义 a[i] 为 too tall.
给定正整数 k, 在 1 次操作中, 你可以将连续 k 个数 + 1(a[i] = a[i] + 1).
输出在任意次操作后, 数组中可以存在最多多少个 too tall 的数.
思路
如果 k=1, 简单 模拟 推演以下便可得到 ans = (int) (n - 1) / 2.
如果 k>1, 如果想把中间的数增大, 不可避免地会增大旁边的数. 从而导致 2 个数的差不变, 无法为形成 too tall 作出贡献. 因此, 所有的操作都是无效的. 只需要输出原始数组有多少个 too tall 即可.
代码


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
#define MAXN (int)2e5+7
int a[MAXN];
signed main(){
//cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
int n,k;cin>>n>>k;
FOR(i,1,n) scanf("%d",&a[i]);
if(k==1) cout<<(n-1)/2<<'\n';
else{
int ans=0;
FOR(i,2,n-1) if(a[i]>a[i-1]+a[i+1]) ans++;
cout<<ans<<'\n';
}
}
return 0;
}
边栏推荐
- Global registration component
- 响应式织梦模板家居家具建材类网站
- 【ARCGIS创建中国南海诸岛及九段线小图框】
- internship:移动端源码的分析
- Power on, press F11, select one shot, and then select U disk to start
- Codeforces Global Round 21 A. NIT orz!
- 会用redis吗?那还不快来了解下redis protocol
- 基于角色的云环境下虚拟机安全访问控制策略
- 访问控制设定
- Massive remote sensing data processing and the practical application of GEE cloud computing technology
猜你喜欢

Easy gene encode histone chip SEQ and transcription factor chip SEQ data standard and processing flow

datax扩展vertica插件

Codeforces Round #802 B. Palindromic Numbers

易基因|ENCODE组蛋白ChIP-seq和转录因子ChIP-seq数据标准及处理流程

QT make color selection control

推荐系统究竟是什么?

腾势全新豪华中大型MPV曝光,安全、舒适一个不落
求助,更新到思源 v2.0.27,dark+ 主题自适应宽度问题

Cloud document management software docuware cloud how to solve five it problems

卸载CUDA11.1
随机推荐
Codeforces Round #802 B. Palindromic Numbers
【C语言初阶】函数学习报告
学习经验分享之六:干货博士经验分享
Ubuntu 22.04 LTS 是目前最安全的版本的七大原因
Timeline和Playable导致Unity崩溃问题记录
量子保密通信浅析
访问控制设定
Win11系统.NET Framework 3.5怎么启用?
USB driver development process
408天勤链表插入排序与双气泡排序课后习题代码
Research on Key Technologies of asset detection in Cyberspace
网络地址转换
[mt2109] rectangle
【ARCGIS创建中国南海诸岛及九段线小图框】
7-Redis架构设计到使用场景-缓存穿透、缓存雪崩、缓存预热、缓存降级
华泰证券开户安全吗,是正规证券公司吗?
A privacy protection and authentication method for fingerprint biometrics
我国数据安全治理研究
6-Redis架构设计到使用场景-持久化机制、缓存失效策略、缓存命中率
Codeforces Round #802 C. Helping the Nature