Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: vachirasawin
Problemset: วันว่างๆ
Language: cpp
Time: 0.016 second
Submitted On: 2026-03-13 17:17:20
// grader-chan
// c2_st66_freeday.cpp | c2_st66_freeday
#include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
vector<pair<int, int>> v;
for (int i = 0; i < N; i++) {
cin >> M;
for (int j = 0; j < M; j++) {
int s, e;
cin >> s >> e;
v.push_back({s, e});
}
}
sort(v.begin(), v.end());
vector<pair<int, int>> merged;
for (auto [l, r] : v) {
if (merged.empty() || merged.back().second < l) {
merged.push_back({l,r});
} else {
merged.back().second = max(merged.back().second, r);
}
}
if (merged.size() == 1) {
cout << -1;
} else {
cout << merged[0].second << " ";
for(int i = 1; i < merged.size() - 1; i++){
cout << merged[i].first << " " << merged[i].second << " ";
}
cout << merged[merged.size() - 1].first << " ";
}
return 0;
}