思路跟题解一样但是过不了样例 悬关
查看原帖
思路跟题解一样但是过不了样例 悬关
1327857
Endless_summer楼主2024/8/20 15:35
#include<bits/stdc++.h>
using namespace std;
int n,h,cnt,ans=0;
bool tree[30005];
struct line{
	int b,e,t;
}L[5005];
bool cmp(line x,line y){
	return (x.e<y.e);
}
int main(){
	cin>>n>>h;
	for(int i=1; i<=h; i++) scanf("%d %d %d",&L[i].b,&L[i].e,&L[i].t);
	sort(L+1,L+1+h,cmp);
	for(int i=1; i<=h; i++){
		cnt=0;
		for(int j=L[i].b; j<=L[i].e; j++) if(tree[i]) cnt++;
		if(cnt>=L[i].t) continue;
		else for(int j=L[i].e; j>=L[i].b; j--){
			if(!tree[i]){
				tree[i]=1;cnt++;ans++;
				if(cnt==L[i].t) break;
			}
		} 
	}
	cout<<ans;
	return 0;
}
2024/8/20 15:35
加载中...