boolcheck(int x){ int p = 0; priority_queue<prog> q; for (int i = 1; i < 20010; ++i) { while (p < n && pr[p].l < i) { q.push(pr[p]); ++p; } int sum = x; while (sum > 0 && !q.empty()) { if (q.top().r < i) { returnfalse; } prog k = q.top(); q.pop(); k.w -= sum; if (k.w > 0) { q.push(k); } sum = -k.w; } if (p == n && q.empty()) { break; } } returntrue; }
intmain(){ scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d%d", &pr[i].l, &pr[i].r, &pr[i].w); } sort(pr, pr + n, cmp); int L = 1, R = n * 1010, ans = R; while (L <= R) { int m = (L + R) >> 1; if (check(m)) { ans = min(ans, m); R = m - 1; } else { L = m + 1; } } printf("%d\n", ans); } return0; }