显然题目就是让我们模拟摸鱼者和老板的智斗。
给出一种简单的模拟方法,考虑到摸鱼的时间都是一段区间,所以我们可以设 表示上一次摸鱼区间的左端点时刻,那么对于每一个 ,上一次摸鱼区间的时长就是 ,那么算完了这个摸鱼区间, 也需要更改成下一个摸鱼区间的左端点时刻,也就是 。
注意计算最后那段可以尽情摸鱼的时长。
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,t;
cin >> n >> t;
int last = 0,ans = 0;
for(int i = 1;i<=n;++i)
{
int x;
cin >> x;
if(last<x)
{
ans+=x-last;
last = x+100;
}
}
if(last<t)
{
ans+=t-last;
}
cout << ans;
return 0;
}