```cpp
#include<bits/stdc++.h>
using namespace std;
const int N = 5e4;
struct SEC{
int l, r, need;
}sec[N];
bool operator < (const SEC &a, const SEC &b)
{
if(a.l != b.l)
return a.l < b.l;
return a.r < b.r;
}
int ans = 0;
int use[N];
int n, m;
int main()
{
cin >> n >> m;
memset(use, 0, sizeof(use));
for(int i = 1; i <= m; i++)
cin >> sec[i].l >> sec[i].r >> sec[i].need;
sort(sec + 1, sec + m + 1);
for(int i = 1; i <= m; i++)
{
int k = 0;
bool f = 0;
for(int j = sec[i].l; j <= sec[i].r; j++)
{
if(use[j])
k++;
if(k == sec[i].need)
{
f = 1;
break;
}
}
if(f)
continue;
int s = sec[i].need - k;
ans += s;
for(int j = sec[i].r; j >= sec[i].l; j--)
{
use[j] = 1;
if(--s == 0)
break;
}
}
cout << ans << endl;
return 0;
}
```
by Starry___sky @ 2020-09-09 21:53:20
```cpp
/*
//法1
#include<bits/stdc++.h>
using namespace std;
struct line {
int s, e, v;
} a[5005];
int n, m, ans = 0;
bool used[30005] = {0};
bool cmp(line a, line b) {
return a.e < b.e;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i].s, &a[i].e, &a[i].v);
sort(a + 1, a + 1 + m, cmp);
for (int i = 1; i <= m; i++) {
int k = 0;
for (int j = a[i].s; j <= a[i].e; j++) if (used[j]) k++;
if (k >= a[i].v) continue;
for (int j = a[i].e; j >= a[i].s; j--) {
if (!used[j]) {
used[j] = 1;
k++;
ans++;
if (k == a[i].v) break;
}
}
}
cout << ans;
return 0;
}
*/
//法2
#include <bits/stdc++.h>
using namespace std;
struct node {
int b, e, t;
} h[5005];
int a[30005]; //打勾用的数组
bool cmp(node a, node b) {
if (a.e != b.e)
return a.e < b.e;
else
return a.t > b.t;
}
int main() {
int n, q, total = 0;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> h[i].b >> h[i].e >> h[i].t;
}
sort(h, h + q, cmp);
for (int i = 0; i < q; i++) {
int g = 0;
for (int j = h[i].b; j <= h[i].e; j++)
g += a[j];
if (g < h[i].t) {
int x = h[i].t - g; // 5-3=2
total += x;
int j = h[i].e;
while (x) {
if (a[j] != 1) {
a[j] = 1;
x--;
}
j--;
}
}
}
cout << total << endl;
for (int i=1; i<=n; i++){
if (a[i]==1) cout << i << " ";
}
return 0;
}
```
by RobinQIN1 @ 2023-03-05 19:07:19