Submission

Status:

[-SSSSSSSSSSSSSSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: onlyme910

Problemset: วันว่างๆ

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-11 09:37:54

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int day[1000000];
int st,ed;
int ts =0 ;
ll int te = 1000000000;

int main(){
    int n;
    cin >> n;
    queue<int> free_st;
    queue<int> free_end;
    queue<int> start;
    queue<int> end;
    for(int i = 0;i<n;i++){
        int c;
        cin >> c;
        for(int j = 0;j<c;j++){
            cin >> st;
            start.push(st);
            if(st > ts){
                ts = st;
            }
            cin >> ed;
            end.push(ed);
            if(ed < te){
                te = ed;
            }
        }
    }
    while(!start.empty()){
        int check_st = start.front();
        start.pop();
        int check_end = end.front();
        end.pop();
        for(int i = check_st;i <= check_end-1;i++){
            day[i] = 1;
        }
    }
    bool find = false;
    for(int i = ts;i <= te-1;i++){
        if(day[i] == 0 && day[i+1] == 1 && !find){
            free_st.push(i);
            free_end.push(i+1);
        }
        else if(day[i] == 0 && day[i+1] == 0){
            if(!find)free_st.push(i);
            find = true;
        }
        else if(day[i] == 0 && day[i+1] == 1 && find){
            free_end.push(i+1);
        }
        if(day[i] == 1){
            find = false;
        }
    }
    if(free_st.empty()){
        cout << "-1";
        return 0;
    }
    while(!free_st.empty()){
        int sd = free_st.front();
        free_st.pop();
        int ed = free_end.front();
        free_end.pop();
        cout << sd << " " << ed;
    }
}