贪心的基本思想,为防止错误要把握好精度。
刷满1000题,与君共勉!!!

//https://ac.nowcoder.com/acm/contest/950/B
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e4 + 5;
struct nowcode
{
    int b, e, t;
} cow[5005];
int q[MAX] = {0};
bool cmp(nowcode one, nowcode two)
{
    return one.e < two.e;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h;
    cin >> n >> h;
    for (int i = 0; i < h; ++i)
    {
        cin >> cow[i].b >> cow[i].e >> cow[i].t;
    }
    sort(cow, cow + h, cmp);
    int ans = 0;
    for (int i = 0; i < h; ++i)
    {
        int count = 0;
        for (int j = cow[i].b; j <= cow[i].e; ++j)
        {
            if (q[j] == 1)
            {
                count++;
            }
        }
        if (count < cow[i].t)
        {
            for (int j = cow[i].e; j >= cow[i].b; --j)
            {
                if (q[j] == 0)
                {
                    q[j] = 1;
                    count++;
                    ans++;
                }
                if (count == cow[i].t)
                {
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}