-
Notifications
You must be signed in to change notification settings - Fork 0
/
1017.cpp
49 lines (48 loc) · 1.16 KB
/
1017.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
#include <bits/stdc++.h>
using namespace std;
const int opentime = 8 * 3600;
const int closetime = 17 * 3600;
struct person{
int artime, prtime;
person(int a, int p){
artime = a;
prtime = p;
}
};
struct window{
int frtime = opentime;
};
vector<person> line;
vector<window> bank;
bool cmp1(const person &a, const person &b){
return a.artime < b.artime;
}
struct cmp2{
bool operator()(int a, int b){
return bank[a].frtime!=bank[b].frtime?bank[a].frtime>bank[b].frtime:a>b;
}
};
int main(){
int n, k;
scanf("%d %d", &n, &k);
bank.resize(k);
priority_queue<int, vector<int>, cmp2> p;
for(int i=0; i<k; i++) p.push(i);
for(int i=0; i<n; i++){
int a, b, c, d;
scanf("%d:%d:%d %d", &a, &b, &c, &d);
int e = a * 3600 + b * 60 + c;
if(e <= closetime) line.push_back(person(e, d));
}
sort(line.begin(), line.end(), cmp1);
double waittime = 0.0;
for(int i=0; i<line.size(); i++){
int now = p.top();
p.pop();
if(line[i].artime < bank[now].frtime) waittime += bank[now].frtime - line[i].artime;
bank[now].frtime = max(line[i].artime, bank[now].frtime) + min(3600, line[i].prtime*60);
p.push(now);
}
printf("%.1f", waittime / 60 / line.size());
return 0;
}