-
Notifications
You must be signed in to change notification settings - Fork 0
/
test17.cpp
53 lines (49 loc) · 1.39 KB
/
test17.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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
using namespace std;
struct Customer
{
int arriveTime{};
int processTime{};
};
int main()
{
int N,K;
cin >> N >> K;
vector<Customer> customers;
for(int i = 0; i < N; i++)
{
int hour, minute, second, processingTime;
char colon;
cin >> hour >> colon >> minute >> colon >> second;
cin >> processingTime;
int time = hour * 3600 + minute * 60 + second;
if(time > 61200) continue; // 17:00:00 = 61200
Customer customer;
customer.arriveTime = time;
customer.processTime = processingTime * 60;
customers.push_back(customer);
}
sort(customers.begin(), customers.end(), [](const Customer& a, const Customer& b) {
return a.arriveTime < b.arriveTime;
});
int total = 0;
priority_queue<int, vector<int>, greater<> > q;
for (int i = 0; i < K; ++i) q.push(28800);
for(auto & customer : customers)
{
if (q.top() <= customer.arriveTime) {
q.push(customer.arriveTime + customer.processTime);
q.pop();
} else {
total += q.top() - customer.arriveTime;
q.push(q.top() + customer.processTime);
q.pop();
}
}
cout << fixed << setprecision(1) << total / (60.0 * customers.size()) << endl;
return 0;
}