AtCoder-ARC073_A Sentou

发布时间 2023-08-08 19:02:52作者: ~CHC~

Sentou

【题意】:

有一个开关,当按下开关后的 T 秒内会一直放水,当在放水状态时,如果有人再次按下开关,那么停止放水,并从按下的那一刻起的 T 秒会再次一直放水,给出 n 个人按压开关的时间,问总共流出多少水

【思路】:

简单模拟

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// #define ios ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const ll N = 1e6 + 10;
void solve()
{
	ll n, t, sum = 0;
	cin >> n >> t;
	vector<ll> a(n + 1);
	for (ll i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++)
	{
		ll l = a[i - 1] + t;
		if (l < a[i]) sum += a[i] - l;
	}
	sum += a[1] - 0;
	cout << a[n] + t - sum << endl;
}
int main()
{
	IOS
	// ll t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}