Advertisement
LZsolar

CodeJam#3

Apr 3rd, 2020
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef pair<int,pair<int,int>> pii;
  4. typedef pair<int,char> pi;
  5.  
  6. int main(){
  7.     int k; scanf("%d",&k);
  8.     for(int t=1;t<=k;t++){
  9.         int n; scanf("%d",&n);
  10.         //char ans[n+1];
  11.         bool canDo=true;
  12.         int c=0,j=0;
  13.         priority_queue<pii,vector<pii>,greater<pii>> q;
  14.         priority_queue<pi,vector<pi>,greater<pi>> ans;
  15.         for(int i=0;i<n;i++){
  16.             int a,b;
  17.             scanf("%d %d",&a,&b);
  18.             q.push({a,{i,b}});
  19.         }
  20.         while(!q.empty()){
  21.             int a=q.top().first,b=q.top().second.second,
  22.             i=q.top().second.first;
  23.             q.pop();
  24.             if(c<=a){
  25.                 ans.push({i,'C'}); c=b;
  26.             }
  27.             else if(j<=a){
  28.                 ans.push({i,'J'}); j=b;
  29.             }
  30.             else{
  31.                 canDo=false; break;
  32.             }
  33.         }
  34.         printf("Case #%d: ",t);
  35.         if(canDo){
  36.             while(!ans.empty()){printf("%c",ans.top().second); ans.pop();}
  37.             printf("\n");
  38.         }
  39.         else{printf("IMPOSSIBLE\n");}
  40.     }
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement