Codeforces Round #535 (Div. 3) E1. Array and Segments (Easy version)

题目链接 : http://codeforces.com/contest/1108/problem/E1

这个博客写的很好  https://www.cnblogs.com/letlifestop/p/10325140.html  看了这个博客才会写

数据范围比较小,直接暴力就行,每一次我就固定一个点,不改变他,只改变不包含这个点的区间,然后求出区间变化后的最大值,最后遍历完所有点后求出最大值

 

#include
using namespace std;
const int INF = 0x3f3f3f3f;
int mp[305], temp[305];
vectorans,lit;
struct node 
{
	int left, right;
};
node coo[305];
int main()
{
	std::ios::sync_with_stdio(false);
	int n, m, cnt,ta,ti, maxn, i, j, k;
	while(cin >> n >> m)
	{
		maxn = -INF;
		ans.clear();
		lit.clear();
		memset(mp, 0, sizeof(mp));
		memset(temp, 0, sizeof(temp));
		cnt = 1;
		for(i = 1; i <= n; i++)
			cin >> mp[i];
		for(i = 1; i <= m; i++)
			cin >> coo[i].left >> coo[i].right;
		for(i = 1; i <= n; i++)
		{
			ta = -INF,ti = INF;
			lit.clear();
			memcpy(temp, mp, sizeof(mp));
			for(j = 1; j <= m; j++)
			{
				if(i<=coo[j].right && i>=coo[j].left)
					continue;
				for(k = coo[j].left; k <= coo[j].right; k++)
					temp[k]--;
				lit.push_back(j);
			}
			for(j = 1; j <= n; j++)
			{
				ta = max(ta, temp[j]);
				ti = min(ti, temp[j]);
			}
			if(maxn < ta-ti)
			{
				maxn = ta-ti;
				ans.swap(lit);
			}
			
		}
		cout << maxn << endl;
		cout << ans.size() << endl;
		if(ans.size())
		{
			cout << ans[0];
			for(i = 1; i < ans.size(); i++)
			{
				cout << " " << ans[i]; 
			}
		}
		
		cout << endl;
		
	} 

	return 0;

} 

 

你可能感兴趣的:(思维)