Repository navigation
Expand file tree
/
Copy pathCall_center.cpp
More file actions
121 lines (105 loc) · 3.87 KB
/
Copy pathCall_center.cpp
File metadata and controls
121 lines (105 loc) · 3.87 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <bits/stdc++.h>
using namespace std;
struct Operator {
int index;
bool isBusy;
int timeToEnd;
int timeToStart;
int peopleCount = 0;
Operator(int index, int timeToStart = 0, int timeToEnd = 0, bool isBusy = false) {
this->timeToStart = timeToStart;
this->timeToEnd = timeToEnd;
this->index = index;
this->isBusy = isBusy;
}
bool operator<(const Operator& other) const {
return this->peopleCount < other.peopleCount;
}
};
int main() {
int n, k;
cin >> n >> k;
vector<Operator> operators;
for (int i = 0; i < k; i++) {
operators.push_back({ i,false });
}
vector<pair<int, int>> clients;
for (int i = 0; i < n; i++) {
bool isDone = false;
int j = i;
int index = j % k;
int start, time;
cin >> start >> time;
if (operators[index].isBusy == false) {
operators[index].timeToStart = start;
operators[index].timeToEnd = start + time;
operators[index].isBusy = true;
operators[index].peopleCount += 1;
}
else if (operators[index].isBusy == true && start >= operators[index].timeToEnd) {
operators[index].peopleCount += 1;
operators[index].timeToStart = start;
operators[index].timeToEnd = start + time;
}
else {
int copy = index+1;
while (copy < k) {
isDone = false;
if (operators[copy].isBusy == false) {
isDone = true;
operators[copy].timeToStart = start;
operators[copy].timeToEnd = start + time;
operators[copy].isBusy = true;
operators[copy].peopleCount += 1;
}
else if (operators[copy].isBusy == true && start >= operators[copy].timeToEnd) {
isDone = true;
operators[copy].peopleCount += 1;
operators[copy].timeToStart = start;
operators[copy].timeToEnd = start + time;
}
copy++;
if (isDone == true) {
break;
}
}
if (isDone == false) {
copy = 0;
while (copy < index) {
isDone = false;
if (operators[copy].isBusy == false) {
isDone = true;
operators[copy].timeToStart = start;
operators[copy].timeToEnd = start + time;
operators[copy].isBusy = true;
operators[copy].peopleCount += 1;
}
else if (operators[copy].isBusy == true && start >= operators[copy].timeToEnd) {
isDone = true;
operators[copy].peopleCount += 1;
operators[copy].timeToStart = start;
operators[copy].timeToEnd = start + time;
}
copy++;
if (isDone == true) {
break;
}
}
}
clients.push_back({ start,time });
}
}
make_heap(operators.begin(), operators.end());
int max = operators.front().peopleCount;
set<int> index;
while (!operators.empty() && operators.front().peopleCount == max) {
index.insert(operators.front().index);
pop_heap(operators.begin(), operators.end());
operators.pop_back();
}
while (!index.empty()) {
cout << *index.begin() << " ";
index.erase(index.begin());
}
return 0;
}