#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 10007;
int n;
struct Node {
int r,d,w;
friend bool operator<(const Node& a, const Node& b) {
return a.d > b.d;
}
}node[maxn];
bool cmp(const Node& a, const Node& b) {
return a.r < b.r;
}
bool IsComplete(int speed) {
priority_queue<Node> q;
int cnt = 0, tick = 1;
//每次走一个单位时间
while (cnt < n || !q.empty()) {
//可以开始执行当前任务
while (cnt < n && node[cnt].r == tick)q.push(node[cnt++]);
//单位时间可以完成的工作
int c = speed;
while (!q.empty() && c > 0) {
Node top = q.top();
q.pop();
int over = min(c, top.w);
c -= over;
top.w -= over;
//工作未完成
if (top.w > 0) q.push(top);
}
//当前时间工作结束
tick++;
//到结束时间还未完成
if (!q.empty() && q.top().d == tick) return false;
}
return true;
}
int main()
{
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> node[i].r >> node[i].d >> node[i].w;
}
sort(node, node + n,cmp);
int l = 1, r = 200000;
while (l < r) {
int mid = (l + r) >> 1;
if (IsComplete(mid)) {
r = mid;
}
else l = mid + 1;
}
cout << l << endl;
}
return 0;
}
uva1422
最新推荐文章于 2024-11-09 20:38:27 发布