Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- bool available(int S, int E, vector<vector<int>> tasks) {
- if(tasks.size()==0) return true;
- else {
- for(int i=0; i<tasks.size(); i++) {
- if((S>=tasks[i][0] && S<tasks[i][1]) || (E>tasks[i][0] && E<=tasks[i][1]) || (S<=tasks[i][0] && E>=tasks[i][1])) return false;
- }
- return true;
- }
- }
- void assignTask(int S, int E, vector<vector<int>> &tasks) {
- if(0<=S && S<=E && E<=1440) {
- tasks.push_back({S, E});
- }
- }
- void solve() {
- int N;
- cin>>N;
- vector<vector<int>> JTasks, CTasks, time;
- // scheduling time
- for(int i=0; i<N; i++) {
- int S,E;
- cin>>S>>E;
- if(0<=S && S<=E && E<= 1440) {
- time.push_back({S, E});
- }
- }
- // assign tasks
- bool possible=true;
- string str="";
- for(int i=0; i<N; i++) {
- int S=time[i][0];
- int E=time[i][1];
- if(available(S,E,CTasks)) {
- assignTask(S,E,CTasks);
- char c='C';
- str.push_back(c);
- continue;
- } else if(available(S,E,JTasks)) {
- assignTask(S,E,JTasks);
- char j='J';
- str.push_back(j);
- continue;
- } else {
- possible=false;
- break;
- }
- }
- if(possible) cout<<str;
- else cout<<"IMPOSSIBLE";
- cout<<"\n";
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int T, i=1;
- cin>>T;
- while(T--) {
- cout<<"Case #"<<i<<": ";
- solve();
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement