-
Notifications
You must be signed in to change notification settings - Fork 0
/
920B Tea Queue.cpp
executable file
·97 lines (81 loc) · 1.28 KB
/
920B Tea Queue.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
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
struct student
{
int l;
int r;
int index;
};
int32_t main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int timecount=0;
student arr[n];
int ans[n];
for(int i=0;i<n;i++)
{
cin >> arr[i].l >> arr[i].r;
arr[i].index=i;
}
vector<student> v(n);
v.clear();
int start=0;
int count=0;
while(count<n)
{
for(int i=start;arr[i].l<=timecount;i++)
{
if(arr[i].l==timecount)
{
v.push_back(arr[i]);
start=i;
}
}
int flag=1;
if(!v.empty())
{
while(flag)
{
if(v.empty())
{
flag=0;
}
else
{
student going = v[0];
if(going.r<timecount)
{
ans[going.index]=0;
v.erase(v.begin());
count++;
}
else
{
ans[going.index]=timecount;
v.erase(v.begin());
count++;
flag=0;
}
}
}
}
timecount++;
}
for(int i=0;i<n;i++)
{
cout << ans[i] << " ";
}
cout << endl;
}
return 0;
}