[IOI2005]mea

IOI

读完题,感觉这个题并不是很难,那我是不是可以去IOI了

最先考虑暴力,发现完全行不通,所以,我们考虑其他方法。突然发现:其实在确定 \(s_1\) 的时候,整个序列就可以确定了,所以我们考虑对 \(s_1\) 进行操作

通过题目中给出的条件,容易发现这个值与奇偶性有关系,所以 code

注意在答案为负的情况下判 0

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#define int long long
using namespace std;
namespace xin_io
{
	inline int get()
	{
		int s = 0,f = 1;
		register char ch = getchar();
		while(!isdigit(ch))
		{
			if(ch == '-') f = -1;
			ch = getchar();
		}
		while(isdigit(ch))
		{
			s = s* 10 + ch - '0';
			ch = getchar();
		}
		return s * f;
	}
	inline void openfile()
	{freopen("t.txt","r",stdin);}
	inline void outfile()
	{freopen("o.txt","w",stdout);}
}
using xin_io::get; using xin_io::openfile; using xin_io::outfile;
namespace xin
{
	int mx = 1ll<<60ll,mn = -mx;
	int now,i,x,y,n;
	inline short main()
	{
		n = get();
		for (i = 1; i <= n; ++i, y = x) 
		{
			x = get();
			if (i & 1) now += x - y,mx = min(mx, now);
			else now += y - x,mn = max(mn,now);
		}
		printf("%lld\n", mx < mn ? 0 : mx - mn + 1);
		return 0;
	}
}
signed main() {return xin::main();}
posted @ 2021-05-05 09:49  NP2Z  阅读(51)  评论(0编辑  收藏  举报