#include <bits/stdc++.h>
using namespace std;
typedef struct
{
int start;
int length;
int end;
} cu;
string t2s(int t)
{
int h = 8 + t / 60;
int m = t % 60;
string temp = "";
if (h < 10)
temp = temp + "0";
temp = temp + to_string(h) + ":";
if (m < 10)
temp = temp + "0";
temp = temp + to_string(m);
return temp;
}
int main()
{
ios::sync_with_stdio(false);
int n, m, count, q;
cin >> n >> m >> count >> q;
cu customer[count + 1];
for (int i = 1; i <= count; i++)
{
cin >> customer[i].length;
}
queue<cu *> qu[n];
int time = 0;
for (int i = 1; i <= count; i++)
{
int man = 1;
int pos;
int minn = 65535;
for (int j = 0; j < n; j++)
{
if (qu[j].size() < m)
{
man = 0;
if (qu[j].size() < minn)
{
minn = qu[j].size();
pos = j;
}
}
}
if (!man)
{
if (qu[pos].empty())
{
customer[i].start = time;
customer[i].end = time + customer[i].length;
qu[pos].push(&customer[i]);
}
else
{
customer[i].start = qu[pos].back()->end;
customer[i].end = customer[i].start + customer[i].length;
qu[pos].push(&customer[i]);
}
}
else
{
for (int j = 0; j < n; j++)
{
if (qu[j].front()->end < minn)
{
minn = qu[j].front()->end;
pos = j;
}
}
time = minn;
customer[i].start = qu[pos].back()->end;
customer[i].end = customer[i].start + customer[i].length;
qu[pos].pop();
qu[pos].push(&customer[i]);
}
}
for (int i = 0; i < q; i++)
{
int t;
cin >> t;
if (customer[t].start >= 540)
cout << "Sorry" << endl;
else
cout << t2s(customer[t].end) << endl;
}
}
PAT(甲) - 1014 Waiting in Line
最新推荐文章于 2022-08-09 15:53:36 发布