-
Notifications
You must be signed in to change notification settings - Fork 0
/
pat 1014(2).cpp
99 lines (97 loc) · 2.59 KB
/
pat 1014(2).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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <cstdio>
#include <queue>
#include <string.h>
#include <cassert>
using namespace std;
struct customer
{
int n;
int eh;
int em;
int process;
};
struct window
{
int line;
int eh;
int em;
bool operator < (const window &b)const
{
if(eh > b.eh)
return true;
else if(eh == b.eh && em > b.em)
return true;
else if(eh == b.eh && em==b.em && line > b.line)
return true;
return false;
}
};
queue <customer> Qu[20];
priority_queue <window> W;
customer C[1002];
int N,M,K,Q;
int main()
{
int i,j,min=1;
customer cu;
window win;
memset(C,0,sizeof(C));
scanf("%d%d%d%d",&N,&M,&K,&Q);
for( i = 1; i <= K; i++)
{
scanf("%d",&C[i].process);
C[i].n=i;
}
for( i= 0 ; i < M; i++)
for( j = 0; j < N; j++)
{
if(min > K)
break;
Qu[j].push(C[min++]);
}
for( i = 0 ; i < N; i++)
{
if(!Qu[i].empty())
{
win.em=Qu[i].front().process;
win.eh=8+win.em/60;
win.em%=60;
win.line=i;
W.push(win);
}
}
while(!W.empty())
{
int line;
win=W.top();
line=win.line;
W.pop();
cu=Qu[line].front();
cu.eh=win.eh;
cu.em=win.em;
assert(win.eh <= 17 && win.eh >=8);
C[cu.n]=cu;
Qu[line].pop();
if(min <= K)
Qu[line].push(C[min++]);
if(win.eh < 17)
{
if(!Qu[line].empty())
{
win.em+=Qu[line].front().process;
win.eh+=win.em/60;
win.em%=60;
W.push(win);
}
}
}
for(i = 0; i < Q; i++)
{
int q;
scanf("%d",&q);
if(C[q].eh!=0)
printf("%02d:%02d\n",C[q].eh,C[q].em);
else
printf("Sorry\n");
}
}