#include <iostream>
using namespace std;
const int N = 387;
int f[N][N];
int main() {
int G, V, n;
scanf("%d%d%d", &G, &V, &n);
for (int i = 1, p, g, v; i <= n; i++) {
scanf("%d%d%d", &p, &g, &v);
for (int j = G; j >= g; --j)
for (int k = V; k >= v; --k)
f[j][k] = max(f[j][k], f[j-g][k-v] + p);
}
printf("%d", f[G][V]);
return 0;
}
转载请注明来源