-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParentingPartneringReturns.cpp
More file actions
89 lines (81 loc) · 2 KB
/
Copy pathParentingPartneringReturns.cpp
File metadata and controls
89 lines (81 loc) · 2 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
// MY SOLUTION TO PARENTING PARTNERING PROBLEM
// https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/000000000020bdf9
#include<bits/stdc++.h>
using namespace std;
bool compare(pair<int,pair<int,int>>i1, pair<int,pair<int,int>>i2)
{
return (i1.second.first < i2.second.first);
}
int main()
{
int t;
cin>>t;
int te=0;
while(t--)
{
int n;
cin>>n;
vector<pair<int,pair<int,int>>>v;
//unordered_map<int,int>up;
vector<int>ans;
for(int i = 0;i<n;i++)
{
pair<int,pair<int,int>>p;
cin>>p.second.first;
cin>>p.second.second;
p.first = i;
//cout<<p.first<< " "<<p.second<<" "<<up[p.second]<<endl;
v.push_back(p);
}
sort(v.begin(),v.end(),compare);
vector<char>res;
char arr[n];
int c_end = 0;
int j_end = 0;
int i=0;
while(i<n)
{
if(v[i].second.first<c_end && v[i].second.first<j_end)
{
//cout<<"IMPOSSIBLE"<<endl;
break;
}
if(v[i].second.first>=c_end)
{
res.push_back('C');
int index = v[i].first;
arr[index] = 'C';
c_end = v[i].second.second;
i++;
}
else{
res.push_back('J');
int index = v[i].first;
arr[index] = 'J';
j_end = v[i].second.second;
i++;
}
}
int l =res.size();
cout<<"Case #"<<te+1<<": ";
if(l!=n)
{
cout<<"IMPOSSIBLE"<<endl;
te++;
continue;
}
res.push_back('\0');
for(int i = 0;i<n;i++)
{
cout<<arr[i];
}
cout<<endl;
/*for(int i =0;i<res.size();i++)
{
cout<<res[i];
}
cout<<endl;*/
te++;
}
}
// SANGEETA JHA