Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: august
Problemset: วันว่างๆ
Language: cpp
Time: 0.010 second
Submitted On: 2026-03-18 19:08:55
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin>> n;
int a[1005]={}, up=0, down=1005;
for (int i=0; i<n; i++) {
int m;
cin>> m;
for (int j=0; j<m; j++) {
int s,e;
cin>> s>> e;
up = max(up,e);
down = min(down, s);
a[s]++;
a[e]--;
}
}
for (int i=1; i<=1000; i++) a[i] += a[i-1];
int i=down;
bool found = false;
while (i<=up) {
if (a[i] == 0) {
int j=i+1;
while (a[j]<1 && j<=up) j++;
if (a[j] >= 1) cout<< i<< ' '<< j<< ' ', found = true;
i=j;
}
else i++;
}
if (!found) cout<< -1;
}