# 【題解】ZeroJudge a829: 主機排程( schedule )

```#include <bits/stdc++.h>
using namespace std;

int t, days, n;
vector <pair<int, int>> va, vb, vc;

int main(){
cin >> t >> days;
while (t--){
cin >> n;
int d, h, l, a, b, c;
for (int i = 0; i < n; i++){
cin >> d >> h >> l >> a >> b >> c;
h += (d-1)*24;
l += h;
if (l > days*24){
l -= days*24;
va.push_back({0, a});
va.push_back({l, -a});
vb.push_back({0, b});
vb.push_back({l, -b});
vc.push_back({0, c});
vc.push_back({l, -c});
l = days*24;
}
va.push_back({h, a});
va.push_back({l, -a});
vb.push_back({h, b});
vb.push_back({l, -b});
vc.push_back({h, c});
vc.push_back({l, -c});
}
cin >> d;
sort(va.begin(), va.end());
sort(vb.begin(), vb.end());
sort(vc.begin(), vc.end());
int s = 0, mx = 0, pre = -1;
for (auto i:va){
if (i.first != pre){
pre = i.first;
mx = max(mx, s);
}
s += i.second;
}
cout << mx << " ";
s = 0;
mx = 0;
pre = -1;
for (auto i:vb){
if (i.first != pre){
pre = i.first;
mx = max(mx, s);
}
s += i.second;
}
cout << mx << " ";
s = 0;
mx = 0;
pre = -1;
for (auto i:vc){
if (i.first != pre){
pre = i.first;
mx = max(mx, s);
}
s += i.second;
}
cout << mx << "\n";
va.clear();
vb.clear();
vc.clear();
}
}
```