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;
    }
}

相关推荐

  1. atcoder ABC 358-B详解

    2024-06-17 01:04:02       34 阅读
  2. B树(B-Tree)详解

    2024-06-17 01:04:02       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-17 01:04:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-17 01:04:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-17 01:04:02       82 阅读
  4. Python语言-面向对象

    2024-06-17 01:04:02       91 阅读

热门阅读

  1. Qt中的事件循环

    2024-06-17 01:04:02       34 阅读
  2. Linux各目录的作用

    2024-06-17 01:04:02       27 阅读
  3. MySQL 保姆级教程(四):过滤数据

    2024-06-17 01:04:02       37 阅读
  4. 一千题,No.0070(组合数的和)

    2024-06-17 01:04:02       31 阅读
  5. 新人学习笔记之(变量)

    2024-06-17 01:04:02       26 阅读
  6. python 如何生成原创文章

    2024-06-17 01:04:02       29 阅读
  7. 车载以太网-TC8测试

    2024-06-17 01:04:02       30 阅读
  8. Go 的 netpoll 如何避免洪泛攻击

    2024-06-17 01:04:02       37 阅读
  9. 10 C++11

    10 C++11

    2024-06-17 01:04:02      23 阅读
  10. Unity3D 如何做好版本控制

    2024-06-17 01:04:02       31 阅读