RT,闲来无事写个贪心
排序后遍历每个屋,能靠后种就往后种
玄学36。1,3,5,10过了,其他WA
代码:
#include <bits/stdc++.h>
using namespace std;
int l[30005],n,m,f,ans;
struct o
{
int x,y,b;
}a[5005];
bool cmp(o a,o b)
{
return a.y < b.y;
}
int main()
{
cin >> n >> m;
for(int i = 0;i < m;i++)
{
cin >> a[i].x >> a[i].y >> a[i].b;
}
sort(a,a + m,cmp);
for(int i = 0;i < m;i++)
{
f = 0;
for(int k = a[i].x - 1;k < a[i].y;k++)
{
if(l[k])
{
f++;
}
}
if(f < a[i].b)
{
f = a[i].b - f;
ans += f;
for(int k = a[i].y - f;k < a[i].y;k++)
{
l[k] = 1;
}
}
}
cout << ans;
return 0;
}