-
Notifications
You must be signed in to change notification settings - Fork 0
/
1014_Waiting_in_Line.cpp
74 lines (64 loc) · 1.77 KB
/
1014_Waiting_in_Line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<climits>
using namespace std;
typedef struct Customer {
int num;
int startTime;
int doneTime;
}cus;
int main() {
int N, M, K, Q;
cin >> N >> M >> K >> Q;
vector<queue<cus>> v(N);
vector<int> time(N, 0);
map<int, cus> m;
int i, t, j = 1, flag = 0;
for (i = 0; i < N*M; ++i) {
cin >> t;
v[i%N].push({i+1, time[i%N], time[i%N]+t});
m.insert({i+1, {i+1, time[i%N], time[i%N]+t}});
time[i%N] += t;
}
for (; i < K; ++i) {
cin >> t;
flag = 0;
int endTime = INT_MAX, tag;
for (int k = 0; k < N; ++k) {
if (v[k].size() < M && v[k].front().doneTime < endTime) {
tag = k;
flag = 1;
}
}
if (flag) {
v[tag].push({i+1, time[tag], time[tag]+t});
m.insert({i+1,{i+1, time[tag], time[tag]+t}});
time[tag] += t;
continue;
}
for (; j < 541; ++j) {
for (int k = 0; k < N; ++k) {
if (v[k].front().doneTime == j) {
v[k].pop();
v[k].push({i+1, time[k], time[k]+t});
m.insert({i+1,{i+1, time[k], time[k]+t}});
time[k] += t;
flag = 1;
}
}
if (flag) { --j; break; }
}
}
for (int i = 0; i < Q; ++i) {
cin >> t;
int mins, hours;
mins = m[t].doneTime % 60;
hours = m[t].doneTime / 60;
if (m[t].startTime >= 540) cout << "Sorry" << endl;
else cout << setfill('0') << setw(2) << 8+hours << ":" << setfill('0') << setw(2) << mins << endl;
}
return 0;
}