#include #define MAX_N 5100 #define INF 1e9 long long dp[MAX_N][MAX_N][2]; int main(void) { int n, w, d; long long tn[MAX_N], wn[MAX_N], vn[MAX_N]; std::cin >> n >> w >> d; for (int i=0; i> tn[i] >> wn[i] >> vn[i]; for (int i=0; i= 0) { if (dp[i+1][v][t]+dp[i+1][v][(t+1)%2] > dp[i][v-vn[i]][t]+dp[i][v-vn[i]][(t+1)%2]+wn[i]) { dp[i+1][v][t] = dp[i][v-vn[i]][t]+wn[i]; dp[i+1][v][(t+1)%2] = dp[i][v-vn[i]][(t+1)%2]; } } else { if (dp[i+1][v][t]+dp[i+1][v][(t+1)%2] > dp[i][v][t]+dp[i][v][(t+1)%2]) { dp[i+1][v][t] = dp[i][v][t]; dp[i+1][v][(t+1)%2] = dp[i][v][(t+1)%2]; } } } } long long ans = 0; for (int v=0; v