Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Segment {
- int left, right, id;
- };
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- int n; cin >> n;
- if (n == 1) {
- cout << "-1 -1" << endl;
- return 0;
- }
- vector<Segment> segs;
- for (int i = 1; i <= n; ++i) {
- int l, r;
- cin >> l >> r;
- segs.push_back(Segment{l, r, i});
- }
- sort(segs.begin(), segs.end(), [](const Segment& a, const Segment& b) {
- return a.left < b.left || (a.left == b.left && (a.right < b.right || (a.right == b.right && a.id < b.id)));
- });
- int prev = 0;
- for (int curr = 1; curr < n; ++curr) {
- assert(segs[prev].left <= segs[curr].left);
- if (segs[curr].right > segs[prev].right) {
- prev = curr;
- } else {
- assert(prev != curr);
- assert(segs[prev].left <= segs[curr].left && segs[curr].right <= segs[prev].right);
- cout << segs[curr].id << " " << segs[prev].id << endl;
- return 0;
- }
- }
- cout << "-1 -1" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement