蒟蒻27分求助,悬赏1关
  • 板块P1250 种树
  • 楼主Maysoul
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/4/1 17:26
  • 上次更新2023/10/23 19:46:03
查看原帖
蒟蒻27分求助,悬赏1关
409774
Maysoul楼主2023/4/1 17:26

AC on #1 #3 #10

贪心思路大致和题解1一样

//2023/4/1
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
int num,ans;
struct house{
	int b;
	int e;
	int t;
}a[50001];
bool vis[300001];
bool cmp(house x,house y)
{
	if(x.e==y.e)
	{
		return x.b>y.b;
	}
	return x.e<y.e;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		cin>>a[i].b>>a[i].e>>a[i].t;
	}
	sort(a+1,a+1+m,cmp);
	for (int i=1;i<=n;i++)
	{
		int k=0;
		for (int j=a[i].b;j<=a[i].e;j++)
		{
			if(vis[j]==1)
			{
				a[i].t--;
			}
		}
		for (int j=a[i].t-1;j>=0;j--)
		{
			int h=a[i].e-j;
			vis[h]=1;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

2023/4/1 17:26
加载中...