Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #define ll long long
- using namespace std;
- int main() {
- ll n;
- cin >> n;
- vector <pair<ll, bool>> X;
- vector <pair<ll, bool>> Y;
- for (ll i = 0; i < n; i++) {
- ll x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- X.push_back({x1, 0}); X.push_back({x2, 1});
- Y.push_back({y1, 0}); Y.push_back({y2, 1});
- }
- sort(X.begin(), X.end());
- sort(Y.begin(), Y.end());
- ll countx = 0, county = 0, res_x1 = -1, res_y1 = -1, res_x2 = -1, res_y2 = -1;
- for (ll i = 0; i < X.size(); i++) {
- !X[i].second ? countx++ : countx--;
- !Y[i].second ? county++ : county--;
- if (countx == n) {
- res_x1 = X[i].first;
- res_x2 = X[i + 1].first;
- }
- if (county == n) {
- res_y1 = Y[i].first;
- res_y2 = Y[i + 1].first;
- }
- }
- if (res_x1 == -1 || res_x2 == -1 || res_y1 == -1 || res_y2 == -1 || res_x2 < res_x1 || res_y2 < res_y1) cout << -1;
- else cout << res_x1 << " " << res_y1 << " " << res_x2 << " " << res_y2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement