-
Notifications
You must be signed in to change notification settings - Fork 0
/
10901.cpp
61 lines (53 loc) · 1.57 KB
/
10901.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
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
static const int LEFT = 0;
static const int RIGHT = 1;
int main()
{
int c;
cin >> c;
while ( c-- )
{
int n, t, m;
cin >> n >> t >> m;
vector<queue<pair<int, int> > > cars(2);
vector<int> uploadedTime(m);
for (int i = 0; i < m; ++i)
{
int arrivalTime;
string bank;
cin >> arrivalTime >> bank;
if (bank == "left")
cars[LEFT].push(pair<int, int>(i, arrivalTime));
else
cars[RIGHT].push(pair<int, int>(i, arrivalTime));
}
int time = 0;
int index = LEFT;
while (! (cars[LEFT].empty() && cars[RIGHT].empty()))
{
int earliest_car = numeric_limits<int>::max();
if (! cars[LEFT].empty())
earliest_car = cars[LEFT].front().second;
if (! cars[RIGHT].empty())
earliest_car = min(earliest_car, cars[RIGHT].front().second);
time = max(time, earliest_car);
int carCount = 0;
while (! cars[index].empty()
&& carCount < n
&& cars[index].front().second <= time)
{
uploadedTime[cars[index].front().first] = time + t;
cars[index].pop();
++carCount;
}
time += t;
index ^= 1;
}
for (int i = 0; i < m; ++i)
cout << uploadedTime[i] << endl;
if (c)
cout << endl;
}
return 0;
}