-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1014.cpp
68 lines (64 loc) · 1.6 KB
/
1014.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
//
// 1014.cpp
// 算法
//
// Created by 王怡凡 on 2017/5/26.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int maxNode = 1111;
int n,m,k,query,q;
int convertToMinute(int h, int m) {
return h*60 + m;
}
struct Window {
int endTime, popTime;
queue<int> q;
}window[20];
int ans[maxNode], needTime[maxNode];
int main() {
int inIndex = 0,i;
scanf("%d %d %d %d",&n,&m,&k,&query);
for(int i=0;i<k;i++) {
scanf("%d",&needTime[i]);
}
for(i=0;i<n;i++) {
window[i].endTime = convertToMinute(8,0);
}
for(i=0;i<min(n*m,k);i++) {
window[inIndex%n].q.push(inIndex);
window[inIndex%n].endTime += needTime[inIndex];
if(inIndex<n) {
window[inIndex].popTime = needTime[inIndex];
}
ans[inIndex] = window[inIndex%n].endTime;
inIndex++;
}
for(;inIndex<k;inIndex++) {
int idx = -1, minPopTime = 1 << 30;
for(i=0;i<n;i++) {
if(window[i].popTime<minPopTime) {
idx = i;
minPopTime = window[i].popTime;
}
}
Window& W = window[idx];
W.q.pop();
W.q.push(inIndex);
W.endTime += needTime[inIndex];
W.popTime += needTime[W.q.front()];
ans[inIndex] = W.endTime;
}
for(i=0;i<query;i++) {
scanf("%d",&q);
if(ans[q-1]-needTime[q-1]>=convertToMinute(17,0)) {
printf("Sorry\n");
} else {
printf("%02d:%02d\n",ans[q-1]/60,ans[q-1]%60);
}
}
return 0;
}