-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10901.cpp
More file actions
83 lines (75 loc) · 2.63 KB
/
uva10901.cpp
File metadata and controls
83 lines (75 loc) · 2.63 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
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;
enum class FS {
left,
right,
};
int main() {
int ncases;
scanf("%d\n", &ncases);
while(ncases--) {
queue<pair<int, int>> lcars, rcars;
vector<pair<int, int>> answer;
int n, t, m,currenttime = 0;;
cin >> n >> t>> m;
FS fs = FS::left;
for(int i = 0; i<m; i++) {
int tmp;
string s;
cin >> tmp >> s;
if (s == "left") {
lcars.push(make_pair(i, tmp));
} else {
rcars.push(make_pair(i, tmp));
}
}
while (not (lcars.empty() and rcars.empty())) {
if(fs == FS::left and not lcars.empty() and lcars.front().second <= currenttime) {
int ncars = 0;
while (not lcars.empty() and lcars.front().second <= currenttime and ncars < n) {
answer.push_back(make_pair(lcars.front().first, currenttime+t));
lcars.pop();
ncars++;
}
currenttime += t;
fs = FS::right;
}
else if(fs == FS::right and not rcars.empty() and rcars.front().second <= currenttime) {
int ncars = 0;
while (not rcars.empty() and rcars.front().second <= currenttime and ncars < n) {
answer.push_back(make_pair(rcars.front().first, currenttime+t));
rcars.pop();
ncars++;
}
currenttime += t;
fs = FS::left;
} else if (fs == FS::left and not rcars.empty() and
(lcars.empty() or lcars.front().second > rcars.front().second)) {
fs = FS::right;
currenttime = max(currenttime, rcars.front().second) + t;
} else if (fs == FS::right and not lcars.empty() and
(rcars.empty() or rcars.front().second > lcars.front().second)) {
fs = FS::left;
currenttime = max(currenttime, lcars.front().second) + t;
} else {
int tmp = INT_MAX;
if (not lcars.empty())
tmp = lcars.front().second;
if (not rcars.empty())
tmp = min(tmp, rcars.front().second);
currenttime = tmp;
}
}
sort(answer.begin(), answer.end());
for (auto p : answer) {
cout << p.second << "\n";
}
if (ncases > 0)
cout << "\n";
}
}