#include <bits/stdc++.h>
using namespace std;
int d, n, f[105][130], ans = 10;
struct rub {
int t, h, f;
bool operator < (const rub& a) const{
return t < a.t;
}
} a[105];
signed main()
{
cin >> d >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].t >> a[i].f >> a[i].h;
sort(a + 1, a + n + 1);
f[0][0] = 10;
for(int i = 1; i <= n; i++) {
for(int j = d + 25; j >= 0; j--) {
if(f[i-1][j] >= a[i].t)
f[i][j] = f[i-1][j] + a[i].f;
if(j >= a[i].h && f[i-1][j - a[i].h] >= a[i].t)
f[i][j] = max(f[i-1][j], f[i-1][j-a[i].h]);
}
}
for(int i = 1; i <= n; i++) {
for(int j = d; j <= d + 25; j++){
if(f[i][j] >= a[i].t){
cout << a[i].t << endl;
return 0;
}
}
if(f[i][0] >= a[i].t)
ans = max(ans, f[i][0]);
}
cout << ans << endl;
}
in
42 25
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 26 5
10 26 5
10 26 5
10 26 6
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
10 25 1
510 1 21
out
510
我的程序判断无解输出 615