跳到正文

题解

题解:AT_abc443_c [ABC443C] Chokutter Addiction

FHQ_Treap约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月1日
收录
2026年2月14日
更新
2026年11月8日
篇幅
约 1 分钟

版本

  1. v1当前

显然题目就是让我们模拟摸鱼者和老板的智斗。

给出一种简单的模拟方法,考虑到摸鱼的时间都是一段区间,所以我们可以设 lastlast 表示上一次摸鱼区间的左端点时刻,那么对于每一个 aia_i,上一次摸鱼区间的时长就是 ai−lasta_i-last,那么算完了这个摸鱼区间,lastlast 也需要更改成下一个摸鱼区间的左端点时刻,也就是 ai+100a_i+100。

注意计算最后那段可以尽情摸鱼的时长。

Code
C++
#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;
}
原文