atcoder ABC 358-B题详解

atcoder ABC 358-B题详解

Problem Statement

At the entrance of AtCoder Land, there is a single ticket booth where visitors line up to purchase tickets one by one. The purchasing process takes A seconds per person. Once the person at the front of the line finishes purchasing their ticket, the next person (if any) immediately starts their purchasing process.

Currently, there is no one in line at the ticket booth, and N people will come to buy tickets one after another. Specifically, the i-th person will arrive at the ticket booth Ti​ seconds from now. If there is already a line, they will join the end of it; if not, they will start the purchasing process immediately. Here, T1​<T2​<⋯<TN​.

For each i (1≤i≤N), determine how many seconds from now the i-th person will finish purchasing their ticket.

Constraints

1≤N≤100
0≤T1​<T2​<⋯<TN​≤106
1≤A≤106
All input values are integers.

Input

The input is given from Standard Input in the following format:

N A
T1​ T2​ … TN​

Output

Print N lines. The i-th line should contain the number of seconds from now that the i-th person will finish purchasing their ticket.

Sample Input 1

3 4
0 2 10

Sample Output 1

4
8
14
The events proceed in the following order:

At 0 seconds: The 1st person arrives at the ticket booth and starts the purchasing process.
At 2 seconds: The 2nd person arrives at the ticket booth and joins the line behind the 1st person.
At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person starts the purchasing process.
At 8 seconds: The 2nd person finishes purchasing their ticket.
At 10 seconds: The 3rd person arrives at the ticket booth and starts the purchasing process.
At 14 seconds: The 3rd person finishes purchasing their ticket.

Sample Input 2

3 3
1 4 7

Sample Output 2

4
7
10
The events proceed in the following order:

At 1 second: The 1st person arrives at the ticket booth and starts the purchasing process.
At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person arrives at the ticket booth and starts the purchasing process.
At 7 seconds: The 2nd person finishes purchasing their ticket, and the 3rd person arrives at the ticket booth and starts the purchasing process.
At 10 seconds: The 3rd person finishes purchasing their ticket.

Sample Input 3

10 50000
120190 165111 196897 456895 540000 552614 561627 743796 757613 991216

Sample Output 3

170190
220190
270190
506895
590000
640000
690000
793796
843796
1041216

思路分析:

本题需要求解每一个人需要的时间,a是解答问题的时间,需要求上一个人的时间加a和当前值加a取最大值,即可以求得每一个人的时间。

code:

#include <iostream>
#include <cmath>
using namespace std;
int n,a;
const int N=110;
int t[N];
int t1[N];//存答案
int main(){cin>>n>>a;for(int i=1;i<=n;i++){cin>>t[i];}t[0]=0;t[n+1]=0;//处理边界for(int i=1;i<=n;i++){t1[i]=max((t1[i-1]+a),(t[i]+a));}for(int i=1;i<=n;i++){cout<<t1[i]<<endl;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/28480.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

paddleocr实验过程

切割数据 Paddleocr/PPOCRLabel/gen_ocr_train_val_test.py&#xff1b;切割后的数据在train_data中&#xff0c;注意切割后的数据前缀默认是当前目录&#xff0c;因此建议切割数据在liunx中进行。建议在liunx中指定 python gen_ocr_train_val_test.py --datasetRootPathXX …

锁存器的工作原理及其在FPGA设计中的注意事项

锁存器&#xff08;Latch&#xff09;是数字电子中常用的一种基本元件&#xff0c;用于在特定的时间点或条件下“锁存”或保存输入的数据值。锁存器对脉冲电平敏感&#xff0c;它只在输入脉冲的高电平&#xff08;或低电平&#xff09;期间对输入信号敏感并改变状态。在数字电路…

React native 使用Animated 优化连续setState 性能问题

再部分场景下我们需要连续更新state刷新页面。一般情况刷新使用setstate没有问题&#xff0c;当需要连续刷新的情况会有明显的性能问题。 场景&#xff1a;自定义可拖动抽屉组件 新增需求在抽屉活动是更新主页面组件样式&#xff0c;此时需要动态传递抽屉高度修改主页组件属性…

vba学习系列(5)--指定区域指定字符串计数

系列文章目录 文章目录 系列文章目录前言一、需求背景二、vba自定义函数1.引入库 总结 前言 一、需求背景 想知道所有客诉项目里面什么项目最多&#xff0c;出现过多少次。 二、vba自定义函数 1.引入库 引用&#xff1a; CountCharInRange(区域,“字符串”) Function CountCh…

AWS无服务器 应用程序开发—第十二章 小结

在使用 AWS 无服务器架构进行开发时,需要注意的事项、易错点、性能优化建议和付费相关的信息: 前端开发(React.js) 注意点和易错点 CORS(跨域资源共享)问题:确保 API 网关设置了正确的 CORS 头。 环境配置:使用 .env 文件来管理环境变量。 构建优化:使用代码分割和…

人有时候不逼自己一把,永远不知道自己有多牛逼!

大家好&#xff0c;我是墨云&#xff0c;一位看起来不像搞技术的IT男。 之前写过一篇文章&#xff0c;从零开始&#xff0c;如何在3个月内吸引3500用户&#xff1a;我的私域运营秘诀&#xff0c;现如今&#xff0c;我们的私域社群成员数已逾五千人。&#x1f46b; 今天的主题&a…

MySQL -- 优化

1. 查询优化 使用索引 示例&#xff1a;有一个包含数百万用户的表&#xff0c;名为 users&#xff0c;常见的查询是通过 email 字段查找用户。 CREATE INDEX idx_email ON users(email);通过创建索引 idx_email&#xff0c;SELECT * FROM users WHERE email exampleexample…

【漏洞复现】红海云eHR PtFjk.mob 任意文件上传漏洞

免责声明&#xff1a; 本文内容旨在提供有关特定漏洞或安全漏洞的信息&#xff0c;以帮助用户更好地了解可能存在的风险。公布此类信息的目的在于促进网络安全意识和技术进步&#xff0c;并非出于任何恶意目的。阅读者应该明白&#xff0c;在利用本文提到的漏洞信息或进行相关测…

【图解IO与Netty系列】Netty编解码器、TCP粘包拆包问题处理、Netty心跳检测机制

Netty编解码器、TCP粘包拆包问题处理、Netty心跳检测机制 Netty编解码器编码器解码器编解码器Netty提供的现成编解码器 TCP粘包拆包问题处理Netty心跳检测机制 Netty编解码器 网络传输是以字节流的形式传输的&#xff0c;而我们的应用程序一般不会直接对字节流进行处理&#x…

Verilog-Behavior Level 和 RTL Level 和 GATE Level的区别

硬件设计中对硬件的描述可以具有不同的抽象级别&#xff0c;以Verilog为例&#xff1a; Behavior Level。描述的是硬件的行为&#xff0c;当我们在看到如下关键字时就是行为级别的代码&#xff1a;#&#xff0c;wait&#xff0c;while&#xff0c;force&#xff0c;release等&…

System-Verilog 实现DE2-115 流水灯

文章目录 一、什么是SystemVerilog二、代码实现实现结果 一、什么是SystemVerilog SystemVerilog是一种硬件描述语言(HDL)&#xff0c;它用于设计和验证电子系统&#xff0c;特别是在集成电路(IC)和系统级芯片(SoC)的设计过程中。SystemVerilog是Verilog语言的一个超集&#xf…

大模型生成的常见Top-k、Top-p、Temperature参数

参考&#xff1a; https://zhuanlan.zhihu.com/p/669661536 topK&#xff0c;topP https://www.douyin.com/video/7380126984573127945 主要是softmax产生的词表每个词的概率分布后&#xff0c; topK&#xff0c;比如K3&#xff0c;表示采样概率最大的前3个&#xff0c;其他全…

【Perl】与【Excel】

引言 perl脚本语言对于文本的处理、转换很强大。对于一些信息量庞大的文本文件&#xff0c;看起来不直观&#xff0c;可以将信息提取至excel表格中&#xff0c;增加数据分析的可视化。perl语言的cpan提供了大量模块。对于excel文件的操作主要用到模块&#xff1a; Spreadshee…

【C++】类相关知识

C 类相关内容 1 默认构造 在C中&#xff0c;如果你遇到了错误信息“the default constructor of ‘B’ cannot be referenced – it is a deleted function”&#xff0c;这通常意味着类B的默认构造函数&#xff08;即不带参数的构造函数&#xff09;被声明为 delete了&#…

C 运算符优先级

在 C 语言中&#xff0c;运算符的优先级决定了在表达式中运算符的计算顺序。以下是 C 语言中运算符优先级表&#xff0c;按从高到低的顺序排列&#xff1a; 1. **括号**: () 2. **后缀运算符**: [] (数组下标), () (函数调用), . (成员访问), -> (指向成员访问), (后缀自…

详解 HBase 的安装部署及命令行操作

一、下载安装 进入 HBase 下载地址&#xff1a;https://archive.apache.org/dist/hbase/ 下载对应版本的 HBase 安装包并上传到虚拟机&#xff0c;并确保安装了 jdk 环境 将 HBase 安装包解压 #在 /opt/software 目录下解压安装包 tar -zxvf hbase-1.3.1-bin.tar.gz -C /opt/…

Android的自启动

最近要用到这个&#xff0c;所以也花时间看看。 从分层来说&#xff0c;安卓的自启动也分成三种&#xff0c;app的自启动&#xff0c;framework服务的自启动&#xff0c;HAL服务的自启动。现在简单说说这三种吧。当然&#xff0c;我主要关注的还是最后一种。。。 一 App的自启…

【论文速读,找找启发点】2024/6/16

ICME 2023 End-To-End Part-Level Action Parsing With Transformer 类似 DETR&#xff0c;通过 加 query的方式实现 端到端 ELAN: Enhancing Temporal Action Detection with Location Awareness 如何实现位置感知&#xff1f; > 重叠的卷积核&#xff1f; Do we really …

大数据开发流程解析

大数据开发是一个复杂且系统的过程&#xff0c;涉及需求分析、数据探查、指标管理、模型设计、ETL开发、数据验证、任务调度以及上线管理等多个阶段。本文将详细介绍每个阶段的内容&#xff0c;并提供相关示例和代码示例&#xff0c;帮助理解和实施大数据开发流程。 本文中的示…

基于WPF技术的换热站智能监控系统02--标题栏实现

1、布局划分 2、准备图片资源 3、界面UI控件 4、窗体拖动和关闭 5、运行效果 走过路过不要错过&#xff0c;点赞关注收藏又圈粉&#xff0c;共同致富&#xff0c;为财务自由作出贡献