:每个项目都用一个优先队列模拟,处理一个人后,就将这个人丢到它的下一项目对应的队列中
#include
#include
#include
#include
#include
using namespace std; const int maxn = 1100; struct node { int t, id; bool operator <(const node &a) const { if (t == a.t) return id > a.id; return t > a.t; } }; int n, m; priority_queue
p[maxn]; queue
q[maxn]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); int x, num, a; node now; for (int i = 0; i < n; i++) { now.id = i; scanf("%d%d", &x, &num); while (num--) { scanf("%d", &a); a--; q[i].push(a); } now.t = x; p[q[i].front()].push(now); } int ans = 0, flag = 1; while (flag) { flag = 0; for (int i = 0; i < m; i++) { if (!p[i].empty()) { flag = 1; now = p[i].top(); if (now.t > ans) continue; p[i].pop(); q[now.id].pop(); if (!q[now.id].empty()) { now.t = ans + 1; p[q[now.id].front()].push(now); } } } ans++; } printf("%d\n", ans-1); } return 0; }