```cpp
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
int n, m;
#define reg register
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) x<y?x:y
struct trash {
int time;
int hight;
int value;
}e[110];
int f[110][110];
int minn=99999999;
inline int read () {
int x = 0; char c;
do c = getchar (); while (c < '0' || c > '9');
while (c >= '0' && c <= '9')
x = x * 10 + c - 48, c = getchar ();
return x;
}
int cmp (trash x, trash y) {
return x.time < y.time;
}
int main () {
m = read (); n = read ();
for (reg int i = 1; i <= n; ++i) {
e[i].time = read ();
e[i].value = read ();
e[i].hight = read ();
}
std::sort (e + 1, e + n + 1, cmp);
f[0][0] = 10;
for (reg int i = 1; i <= n; ++i) {
for (reg int j = m; j >= 0; --j) {
if (!f[i-1][j] || f[i-1][j] < e[i].time) continue;
int cur=min(m,j+e[i].hight);
f[i][cur] = max (f[i][cur],f[i - 1][j]);
if(f[i][m])minn=min(minn,e[i].time);
f[i][j] = f[i-1][j] + e[i].value;
}
}
if(f[n][m])printf("%d\n",minn);
else{
int maxn=0;
for(reg int i=1;i<=n;i++)maxn=max(maxn,f[i][0]);
printf ("%d\n", maxn);
}
}
```
帮你改了下,现在AC了qwq。具体的问题相信你自己也能发现了(其实是我不会解释owo)
by Tony321 @ 2018-08-17 22:42:15