Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #define ll long long
  5. using namespace std;
  6.  
  7. int main() {
  8.     ll n;
  9.     cin >> n;
  10.     vector <pair<ll, bool>> X;
  11.     vector <pair<ll, bool>> Y;
  12.     for (ll i = 0; i < n; i++) {
  13.         ll x1, y1, x2, y2;
  14.         cin >> x1 >> y1 >> x2 >> y2;
  15.         X.push_back({x1, 0}); X.push_back({x2, 1});
  16.         Y.push_back({y1, 0}); Y.push_back({y2, 1});
  17.     }
  18.  
  19.     sort(X.begin(), X.end());
  20.     sort(Y.begin(), Y.end());
  21.  
  22.     ll countx = 0, county = 0, res_x1 = -1, res_y1 = -1, res_x2 = -1, res_y2 = -1;
  23.     for (ll i = 0; i < X.size(); i++) {
  24.         !X[i].second ? countx++ : countx--;
  25.         !Y[i].second ? county++ : county--;
  26.  
  27.  
  28.         if (countx == n) {
  29.             res_x1 = X[i].first;
  30.             res_x2 = X[i + 1].first;
  31.         }
  32.         if (county == n) {
  33.             res_y1 = Y[i].first;
  34.             res_y2 = Y[i + 1].first;
  35.         }
  36.     }
  37.  
  38.     if (res_x1 == -1 || res_x2 == -1 || res_y1 == -1 || res_y2 == -1 || res_x2 < res_x1 || res_y2 < res_y1) cout << -1;
  39.     else cout << res_x1 << " " << res_y1 << " " << res_x2 << " " << res_y2;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement