【PAT A-1014】Waiting in Line
C++代码
#include <bits/stdc++.h>
using namespace std;
using gg = long long;
struct Customer {
gg endTime, num, w;
Customer(gg e, gg n, gg ww) : endTime(e), num(n), w(ww) {}
};
bool operator<(const Customer& c1, const Customer& c2) {
return tie(c1.endTime, c1.w) > tie(c2.endTime, c2.w);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
gg ni, mi, ki, qi, ai, endTime = 17 * 60;
cin >> ni >> mi >> ki >> qi;
vector<gg> ans(ki, INT_MAX);
priority_queue<Customer> customers;
vector<gg> peopleNum(ni), time(ni, 8 * 60);
for (gg i = 0; i < ki; ++i) {
cin >> ai;
if (customers.size() == ni * mi) {
auto c = customers.top();
customers.pop();
peopleNum[c.w]--;
}
gg j = min_element(peopleNum.begin(), peopleNum.end()) - peopleNum.begin();
peopleNum[j]++;
if (time[j] >= endTime) {
continue;
}
time[j] += ai;
customers.push(Customer(time[j], i, j));
ans[i] = time[j];
}
for (gg i = 0; i < qi; ++i) {
cin >> ai;
if (ans[ai - 1] == INT_MAX) {
cout << "Sorry\n";
} else {
cout << setfill('0') << setw(2) << ans[ai - 1] / 60 << ":" << setw(2)
<< ans[ai - 1] % 60 << "\n";
}
}
return 0;
}