-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcollecting_packeges.cpp
More file actions
executable file
·98 lines (88 loc) · 2.58 KB
/
collecting_packeges.cpp
File metadata and controls
executable file
·98 lines (88 loc) · 2.58 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
// g++ collecting_packeges.cpp -o collecting_packeges && ./collecting_packeges
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL)
#define endl '\n'
#define ll long long int
using namespace std;
#define pii pair <ll , ll >
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define loop(x) for (int i = 0; i < x; i++)
bool fun(pair<int, int> a, pair<int, int> b){
return a.first < b.first;
}
int lower(vector<pair<int, int>> pkg, int a){
int l, h;
l = 0;
h = pkg.size();
int m;
while (h >= l){
m = (l+h)/2;
if (pkg[m].first == a){
if (pkg[m-1].first < a) return m;
else h = m-1;
}
else if (pkg[m].first < a) l = m+1;
else h = m-1;
}
}
int upper(vector<pair<int, int>> pkg, int a){
int l, h;
l = 0;
h = pkg.size();
int m;
while (h >= l){
m = (l+h)/2;
if (pkg[m].first == a){
if (pkg[m+1].first > a) return m;
else h = m-1;
}
else if (pkg[m].first < a) l = m+1;
else h = m-1;
}
}
int main(){
fastio;
int t;
cin >> t;
while (t--) {
vector<bool> uniquex(1001, false);
int n;
cin >> n;
vector<pair<int, int>> packages(n);
loop(n) {
cin >> packages[i].first >> packages[i].second;
uniquex[packages[i].first] = true;
}
sort(packages.begin(), packages.end(), fun);
int flag = 0;
string ans = "";
int crr_maxX = 0;
int crr_maxY = 0;
for (int i = 0; i <= 1000; i++){
if (uniquex[i]){
for (int j = crr_maxX; j < i; j++) ans += 'R';
int lb = lower(packages, i);
int ub = upper(packages, i);
int num = ub - lb +1;
int tempY = crr_maxY;
for(int j = crr_maxX ; j < crr_maxX + num; j++){
if (packages[j].second < crr_maxY) {
flag = 1;
break;
}
else tempY = packages[j].second > tempY ? packages[j].second : tempY;
}
}
if (flag == 1) break;
}
if (flag == 1) cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << ans << endl;
}
}
}