Advertisement
dmkozyrev

c.cpp

Apr 30th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Segment {
  6.     int left, right, id;
  7. };
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(0); cout.tie(0);
  12.    
  13.     int n; cin >> n;
  14.    
  15.     if (n == 1) {
  16.         cout << "-1 -1" << endl;
  17.         return 0;
  18.     }
  19.    
  20.     vector<Segment> segs;
  21.     for (int i = 1; i <= n; ++i) {
  22.         int l, r;
  23.         cin >> l >> r;
  24.         segs.push_back(Segment{l, r, i});
  25.     }
  26.    
  27.     sort(segs.begin(), segs.end(), [](const Segment& a, const Segment& b) {
  28.         return a.left < b.left || (a.left == b.left && (a.right < b.right || (a.right == b.right && a.id < b.id)));
  29.     });
  30.    
  31.     int prev = 0;
  32.     for (int curr = 1; curr < n; ++curr) {
  33.         assert(segs[prev].left <= segs[curr].left);
  34.         if (segs[curr].right > segs[prev].right) {
  35.             prev = curr;
  36.         } else {
  37.             assert(prev != curr);
  38.             assert(segs[prev].left <= segs[curr].left && segs[curr].right <= segs[prev].right);
  39.             cout << segs[curr].id << " " << segs[prev].id << endl;
  40.             return 0;
  41.         }
  42.     }
  43.     cout << "-1 -1" << endl;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement