#include <iostream> #include <cmath> #include <cstring> #include <algorithm> using namespace std; struct node { int h; int c; int a; }data[400]; int f[40001]; bool cmp(const node& A, const node& B) { if(A.a == B.a) return A.h > B.h; return A.a < B.a; } int main() { //freopen("1.txt", "r", stdin); int n; while(cin >> n) { memset(f, -1, sizeof(f)); f[0] = 0; for(int i = 0; i < n; i++) cin >> data[i].h >> data[i].a >> data[i].c; sort(data, data + n, cmp); int ans = 0; for(int i = 0; i < n; i++) { int count = 1; int sum = 0; while(sum < data[i].c) { for(int j = data[i].a; j >= count * data[i].h; j--) { if(f[j - count * data[i].h] != -1) f[j] = max(f[j], f[j - count * data[i].h] + count * data[i].h); //if(f[j] > ans) ans = f[j]; } sum += count; if(sum + count * 2 > data[i].c) count = data[i].c - sum; else count *= 2; } } for(int i = data[n - 1].a; i >= 0; i--) { if(f[i] != -1) { ans = f[i]; break; } } cout << ans << endl; } return 0; }