AT2555 题解

· · 题解

AT2555 题解

题目指标 [ARC073A] Sentou .

该文章同步发表于 我的博客 内。

审核一经通过,他人不得盗用博客。若未通过,引用时需注明出处,并私信作者。

正解

其实这题就是一道非常适合初学者做的大模拟。

我们可以将 p_i 设为第 i 个人对水产生影响的时刻。

于是我们回到文章中进行阅读,可以发现:

p_i=t_i+T

同样的,对其进行分类讨论即可。

  1. 如果水已经停了,则用户对水的贡献为 T .

  2. 如果水还没有停,我们要进行去重操作:

t_i-(p_{i-1}-T)

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,q,t,s,p;
int main()
{
    scanf("%lld%lld",&n,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&q);
        if(q<=p) s+=t+q-p;
        else s+=t;
        p=t+q;
    }
    return !printf("%lld",s);
}