题目3 : Registration Day
- 时间限制:10000ms
- 单点时限:1000ms
- 内存限制:256MB
描述
It's H University's Registration Day for new students. There are M offices in H University, numbered from 1 to M. Students need to visit some of them in a certain order to finish their registration procedures. The offices are in different places. So it takes K units of time to move from one office to another.
There is only one teacher in each office. It takes him/her some time to finish one student's procedure. For different students this time may vary. At the same time the teacher can only serve one student so some students may need to wait outside until the teacher is available. Students who arrived at the office earlier will be served earlier. If multiple students arrived at the same time they will be served in ascending order by student number.
N new students need to finish his/her registration. They are numbered from 1 to N. The ith student's student number is Si. He will be arrived at H University's gate at time Ti. He needs to visit Pi offices in sequence which are Oi,1, Oi,2, ... Oi,Pi. It takes him Wi,1, Wi,2, ... Wi,Pi units of time to finish the procedure in respective offices. It also takes him K units of time to move from the gate to the first office.
For each student can you tell when his registration will be finished?
输入
The first line contains 3 integers, N, M and K. (1 <= N <= 10000, 1 <= M <= 100, 1 <= K <= 1000)
The following N lines each describe a student.
For each line the first three integers are Si, Ti and Pi. Then following Pi pairs of integers: Oi,1, Wi,1, Oi,2, Wi,2
, ... Oi,Pi, Wi,Pi.
(1 <= Si <= 2000000000, 1 <= Ti <= 10000, 1 <= Pi <= M, 1 <= Oi,j <= M, 1 <= Wi,j <= 1000)
输出
For each student output the time when he finished the registration.
样例提示
Student 1600012345 will be arrived at the gate at time 500. He needs to first visit Office #1 and then Office #2. He will be arrived at office #1 at time 600. He will leave office #1 at time 1100. Then He will arrive at office #2 at 1200. At the same time another student arrives at the same office too. His student number is smaller so he will be served first. He leaves Office #2 at 1700. End of registration.
Student 1600054321 will be arrived at the gate at time 1100. He will be arrived at Office #2 at 1200. Another student with smaller student number will be served first so he waits for his turn until 1700. He leaves Office #2 at 2000. End of registration.
样例输入
2 2 100
1600012345 500 2 1 500 2 500
1600054321 1100 1 2 300
样例输出
1700
2000
参考答案1:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define fst first
#define snd second
const int MAXN = 100010;
const ll inf = 1000000000000LL;
vector<pii> ow[10010];
//priority_queue<pii, vector<pii>, greater<pii>> pq[110];
ll e[10010];
int lst[10010];
int main(void) {
map<int, int> sid;
int n, m, K;
cin >> n >> m >> K;
//for (int i = 1; i <= m; ++ i) e[i].fst = inf;
vector<ll> s(n), t(n), p(n);
for (int i = 0; i < n; ++ i) {
lst[i] = 0;
cin >> s[i] >> t[i] >> p[i];
sid[s[i]] = i;
e[i] = t[i] + K;
for (int j = 0; j < p[i]; ++ j) {
ll o, w;
cin >> o >> w;
ow[i].emplace_back(pii(o, w));
/*
if (j == 0 && (t[i] + K < e[o].fst || (t[i] + K == e[o].fst && e[o].snd > s[i]))) {
e[o].fst = t[i] + K;
e[o].snd = s[i];
}
*/
}
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
for (int i = 0; i < n; ++ i) pq.push(pii(e[i], s[i]));
vector<ll> curt(m + 1, 0);
vector<ll> ans(n);
while ( !pq.empty() ) {
ll ee = inf, eid = 0;
/*
for (int i = 0; i < n; ++ i) if (lst[i] < p[i]) {
if (e[i] < ee || (e[i] == ee && s[eid] > s[i])) {
eid = i;
ee = e[i];
}
}
*/
/*
for (int i = 1; i <= m; ++ i) {
if (!pq[i].empty() && pq[i].top().fst < ee) {
ee = pq[i].top().fst;
eid = i;
}
}
*/
ee = pq.top().fst, eid = sid[pq.top().snd];
pq.pop();
//if (ee == inf) break;
int id = ow[eid][lst[eid]].fst;
//pii cur = pq[eid].top(); pq[eid].pop();
//ll time = cur.fst;
//ll id = sid[cur.snd];
//cerr << eid << ' ' << id << ' ' << e[eid] << endl;
if (lst[eid] >= (ll)ow[eid].size() - 1) {
ans[eid] = max(e[eid], curt[id]) + ow[eid][lst[eid]].snd;
e[eid] = ans[eid];
curt[id] = ans[eid];
} else {
//ll nid = ow[eid][lst[eid] + 1].fst;
ll ntime = max(e[eid], curt[id]) + ow[eid][lst[eid]].snd + K;
curt[id] = ntime - K;
e[eid] = ntime;
pq.push(pii(ntime, s[eid]));
}
++ lst[eid];
}
for (int i = 0; i < n; ++ i) cout << ans[i] << endl;
return 0;
}