Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cstring>
- #include<vector>
- #include<algorithm>
- using namespace std;
- struct activity{
- int start;
- int end;
- };
- bool compareByStart(const activity &a, const activity &b){
- return a.start < b.start;
- }
- int main(){
- int T;
- cin >> T;
- for(int z = 0; z < T; z++){
- int N;
- cin >> N;
- vector<activity> array;
- string schedule = "";
- int C_end = 0, J_end = 0;
- int not_ok = 1;
- for(int i = 0; i < N; i++){
- activity a;
- cin >> a.start >> a.end;
- array.push_back(a);
- }
- sort(array.begin(), array.end(), compareByStart);
- cout << "Case #" << z + 1 << ": ";
- schedule += "C";
- C_end = array[0].end;
- for(int i = 1; i < array.size(); i++){
- if(array[i].start >= C_end){
- schedule += "C";
- C_end = array[i].end;
- }
- else{
- if(array[i].start >= J_end){
- schedule += "J";
- J_end = array[i].end;
- }
- else{
- not_ok = 0;
- cout << "IMPOSSIBLE\n";
- break;
- }
- }
- }
- if(not_ok == 0){
- continue;
- }
- else{
- cout << schedule << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement