73分求助
  • 板块P1250 种树
  • 楼主Qiqi_Hun
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/24 10:31
  • 上次更新2023/11/2 18:22:53
查看原帖
73分求助
792077
Qiqi_Hun楼主2023/9/24 10:31

WA了3个点

#include <bits/stdc++.h>
using namespace std;
int m,h,have_tree[11451400],ans;
struct edge{
	int s,f,sum;// e[i].s:线段起点 e[i].f:线段终点 e[i].sum:要求的点的个数
}e[11451400];
bool cmp(edge x,edge y)
{
	return x.f<y.f;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>m>>h;
	for(int i=1;i<=h;i++)
	{
		cin>>e[i].s>>e[i].f>>e[i].sum;
	}
	sort(e+1,e+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		int now=0;
		for(int j=e[i].s;j<=e[i].f;j++) now+=have_tree[j];
		if (now>=e[i].sum) continue;
		now=e[i].sum-now;
		int j=e[i].f+1;
		while(now)
		{
			j--;
			if(have_tree[j]) continue;
			have_tree[j]=1;
			ans++;
			now--;
		}
	}
	cout<<ans;
	return 0;
}
2023/9/24 10:31
加载中...