其他分享
首页 > 其他分享> > Sentou

Sentou

作者:互联网

问题 G: Sentou
时间限制: 1 Sec 内存限制: 128 MB

题目描述
In a public bath, there is a shower which emits water for T seconds when the switch is pushed.
If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person will push the switch ti seconds after the first person pushes it.
How long will the shower emit water in total?

Constraints
1≤N≤200,000
1≤T≤109
0=t1<t2<t3<,…,<tN−1<tN≤109
T and each ti are integers.
输入
Input is given from Standard Input in the following format:
N T
t1 t2 … tN
输出
Assume that the shower will emit water for a total of X seconds. Print X.
样例输入 Copy
2 4
0 3
样例输出 Copy
7
提示
Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int UNINF=-0x3f3f3f3f;
const int INF=0x3f3f3f3f;
const int maxn=2e5+7;
inline int read(){
	int x=0,zf=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') zf=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return zf*x;
}
#define read read()
//priority_queue<int,vector<int>,greater<int> >v;
int s[maxn];
int main(){
	int n,t;
	cin>>n>>t;
	int ans=t;
	int ip=t;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<n;i++){
		if(s[i]+t>s[i+1]) ans+=s[i+1]-s[i];
		else ans+=t;
	}
	cout<<ans;
	
	return 0;
} 

标签:shower,ch,int,water,Sentou,seconds,will
来源: https://blog.csdn.net/weixin_51461002/article/details/113949193