#include #include #include #include using namespace std; int N; typedef pair > sch_t; sch_t make_sch(int b, int e, int w){ sch_t s; s.first = -w; s.second.first = b; s.second.second = e; return s; } typedef list lisch; typedef lisch::iterator lisp; lisch ls; int maxval; int reserve[400]; bool isFree(lisp p){ for(int i = p->second.first; i<=p->second.second; i++){ if(reserve[i] >= 2){ return false; } } return true; } void inc(lisp p){ for(int i = p->second.first; i<=p->second.second; i++){ reserve[i]++; } } void dec(lisp p){ for(int i = p->second.first; i<=p->second.second; i++){ reserve[i]--; } } void solve(lisp p, int val){ if(p == ls.end()){ return; } lisp q = p; q++; int nokori = 0; for(lisp r = q; r != ls.end(); r++){ nokori -= r->first; } if(isFree(p)){ inc(p); if(val - p->first > maxval){ maxval = val - p->first;; } if(val - p->first + nokori > maxval){ solve(q, val - p->first); } dec(p); } if(val + nokori > maxval){ solve(q, val); } } int main(){ ifstream cin("hall.txt"); while(cin >> N){ if(N == 0){ break; } ls.clear(); for(int i=0; i<400; i++){ reserve[i] = 0; } for(int i=0; i> b >> e >> w; ls.push_back(make_sch(b, e, w)); } ls.sort(); maxval = 0; solve(ls.begin(), 0); cout << maxval << endl; } return 0; }