#include #include #include #include using namespace std; struct App { int begin, price; }; typedef vector Apps; int main() { int N; ifstream is("hall.txt"); while (is >> N, N != 0) { Apps apps[366]; for (int i = 0; i < N; i++) { int x, y, w; is >> x >> y >> w; App a; a.begin = x; a.price = w; apps[y].push_back(a); } int best[366][366]; for (int i = 0; i < 366; i++) { for (int j= 0; j < 366; j++) { best[i][j] = 0; } } for (int i = 1; i < 366; i++) { for (Apps::iterator ii = apps[i].begin(); ii != apps[i].end(); ii++) { for (int j = 0; j < i; j++) { best[i][j] = max(best[i][j], best[ii->begin-1][j] + ii->price); } for (Apps::iterator jj = ii+1; jj != apps[i].end(); jj++) { best[i][i] = max(best[i][i], best[ii->begin-1][jj->begin-1] + ii->price + jj->price); } } for (int j = 1; j <= i; j++) { best[i][j] = max(best[i][j], best[i][j-1]); best[i][j] = max(best[i][j], best[i-1][j]); best[j][i] = best[i][j]; } } cout << best[365][365] << endl; } }