Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef pair<int,pair<int,int>> pii;
- typedef pair<int,char> pi;
- int main(){
- int k; scanf("%d",&k);
- for(int t=1;t<=k;t++){
- int n; scanf("%d",&n);
- //char ans[n+1];
- bool canDo=true;
- int c=0,j=0;
- priority_queue<pii,vector<pii>,greater<pii>> q;
- priority_queue<pi,vector<pi>,greater<pi>> ans;
- for(int i=0;i<n;i++){
- int a,b;
- scanf("%d %d",&a,&b);
- q.push({a,{i,b}});
- }
- while(!q.empty()){
- int a=q.top().first,b=q.top().second.second,
- i=q.top().second.first;
- q.pop();
- if(c<=a){
- ans.push({i,'C'}); c=b;
- }
- else if(j<=a){
- ans.push({i,'J'}); j=b;
- }
- else{
- canDo=false; break;
- }
- }
- printf("Case #%d: ",t);
- if(canDo){
- while(!ans.empty()){printf("%c",ans.top().second); ans.pop();}
- printf("\n");
- }
- else{printf("IMPOSSIBLE\n");}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement