1 #include <stdio.h>
2 #include <string.h>
3 #include <algorithm>
4 using namespace std;
5 #define INF 0x3f3f3f3f
6 const int maxn = 1000 + 5;
7 int n, m, k, q;
8 int serv[maxn], done[maxn];
9 int line[25][maxn], s[maxn], f[maxn];
10
11 int main() {
12 while(scanf("%d%d%d%d", &n, &m, &k, &q) == 4) {
13 for(int i = 1; i <= k; i++)
14 scanf("%d", &serv[i]);
15 for(int i = 1; i <= n; i++) {
16 s[i] = f[i] = 1;
17 done[i] = serv[i];
18 line[i][1] = i;
19 }
20 for(int i = n+1; i <= k; i++) {
21 bool full = 1;
22 int cnt = m + 1, bet = 1;
23 for(int j = 1; j <= n; j++) {
24 if(f[j] - s[j] + 1 < m) {
25 full = 0;
26 if(f[j] - s[j] + 1 < cnt) {
27 cnt = f[j] - s[j] + 1;
28 bet = j;
29 }
30 }
31 }
32 if(full) {
33 int over_time = INF;
34 bet = 1;
35 for(int j = 1; j <= n; j++) {
36 int id = line[j][s[j]];
37 if(done[id] < over_time) {
38 bet = j;
39 over_time = done[id];
40 }
41 }
42 s[bet] += 1;
43 }
44 f[bet] += 1;
45 line[bet][f[bet]] = i;
46 done[i] = done[line[bet][f[bet]-1]] + serv[i];
47
48 }
49 int qID;
50 for(int i = 0; i < q; i++) {
51 scanf("%d", &qID);
52 if(done[qID] - serv[qID] >= (17-8)*60)
53 printf("Sorry\n");
54 else
55 printf("%02d:%02d\n", done[qID]/60+8, done[qID]%60);
56 }
57 }
58 return 0;
59 }
\[x + y*\frac{5}{x}\]
### 你好啊
我是你们的新朋友flyawayl