Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define INF INT_MAX
- #define LINF LLONG_MAX
- #define forin(data) for(auto &i : data)
- #define debug(x) cerr << #x << " = " << x << endl;
- using ll = long long;
- using pi = pair<int, int>;
- using vi = vector<int>;
- using vii = vector<vi>;
- using vl = vector<ll>;
- void init(){
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- freopen("log.txt", "w", stderr);
- #else
- cin.tie(0); cout.tie(0);
- ios_base::sync_with_stdio(0);
- #endif
- }
- bool sortStartTime(vi &v1, vi &v2){
- return v1[0] < v2[0];
- }
- bool sortIndex(vi &v1, vi &v2){
- return v1[2] < v2[2];
- }
- int main(){
- init()
- int tc;
- cin >> tc;
- for(int i=1; i<=tc; i++){
- bool check = true;
- int n, index = 0;
- cin >> n;
- string ans = "";
- vii arr(n, vi(4));
- for(int i=0; i<n; i++){
- cin >> arr[i][0] >> arr[i][1];
- arr[i][2] = i;
- }
- sort(arr.begin(), arr.end(), sortStartTime);
- int j, c;
- j = c = -1;
- for(int i=0; i<n; i++){
- if(arr[i][0] >= j){
- j = -1;
- }
- if(arr[i][0] >= c){
- c = -1;
- }
- if(j != -1 && c != -1){
- check = false;
- break;
- }
- if(j == -1){
- j = arr[i][1];
- arr[i][3] = 0;
- //ans += "J";
- //cout << "J Assigned! Cost: " << j << endl;
- }else{
- c = arr[i][1];
- arr[i][3] = 1;
- //ans += "C";
- //cout << "C Assigned! Cost: " << c << endl;
- }
- }
- sort(arr.begin(), arr.end(), sortIndex);
- if(!check){
- ans = "IMPOSSIBLE";
- }else{
- for(int i=0; i<n; i++){
- ans += (arr[i][3] == 0 ? "J" : "C");
- }
- }
- cout << "Case #" << i << ": " << ans << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment