int n, W; int v[MAXn + 10]; int w[MAXn + 10]; int team[MAXn + 10][MAXn + 10]; int d[MAXW + 10];
inlineintread(){ registerchar c; for (c = getchar(); (c < '0' || c >'9') && c != '-'; c = getchar()); registerbool f = c == '-'; registerint s = f ? 0 : c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) { s = (s << 3) + (s << 1) + c - '0'; } return f ? -s : s; }
voidput_in(){ W = read(); n = read(); int teamid; for (int i = 1; i <= n; i++) { w[i] = read(); v[i] = read(); teamid = read(); team[teamid][++team[teamid][0]] = i; } }
voidrec(int v[], int w[], int W) { for (int i = 1; i <= MAXn; i++) { if (team[i][0]) { for (int j = W; j >= 0; j--) { for (int k = 1; k <= team[i][0]; k++) { if (j >= w[team[i][k]]) d[j] = max(d[j], d[j - w[team[i][k]]] + v[team[i][k]]); } } } } }
inteva_maxV(int d[], int W){ int ans = -INF; for (int i = 0; i <= W; i++) ans = max(ans, d[i]); return ans; }