Advertisement
ccbeginner

code jam Parenting Partnering Returns

Apr 4th, 2020
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. //code jam Parenting Partnering Returns
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. struct T{
  6.     int S, E, idx;
  7.     char ans;
  8. }arr[1000];
  9.  
  10. bool cmp1(T a, T b){return a.S <= b.S;}
  11. bool cmp2(T a, T b){return a.idx <= b.idx;}
  12.  
  13. int main(){
  14.     for(int i = 0; i < 1000; ++i)arr[i].idx = i;
  15.     int t;
  16.     cin >> t;
  17.     for(int c = 1; c <= t; ++c){
  18.         int n;
  19.         cin >> n;
  20.         for(int i = 0; i < n; ++i)cin >> arr[i].S >> arr[i].E;
  21.         sort(arr, arr+n, cmp1);
  22.         int L1 = 0, L2 = 0;//last end time
  23.         bool can = 1;
  24.         for(int i = 0; i < n; ++i){
  25.             if(L1 <= arr[i].S){
  26.                 arr[i].ans = 'C';
  27.                 L1 = arr[i].E;
  28.             }else if(L2 <= arr[i].S){
  29.                 arr[i].ans = 'J';
  30.                 L2 = arr[i].E;
  31.             }else{
  32.                 can = 0;
  33.                 break;
  34.             }
  35.         }
  36.         sort(arr, arr+n, cmp2);
  37.         cout << "Case #" << c << ": ";
  38.         if(can == 0)cout <<"IMPOSSIBLE\n";
  39.         else{
  40.             for(int i = 0; i < n; ++i)cout << arr[i].ans;
  41.             cout << endl;
  42.         }
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement