Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- pair<int, int> f1(int l1, int l2, int r1, int r2, int s1, int s2, int d1, int d2){
- if (s1+d1 < s2){
- return {s1, s2};
- }
- else if (l1 + d1 > r2-d2){
- return {-1, -1};
- }
- else{
- s1 = s2-d1;
- s1 = max(l1, s1);
- if (s1+d1 >= s2){
- s2 = s1+d1;
- s2 = min(s2, r2);
- }
- if (s1+d1 <= s2){
- return {s1, s2};
- }
- else return {-1, -1};
- }
- }
- pair<int, int> f2(int l1, int l2, int r1, int r2, int s1, int s2, int d1, int d2){
- if (s1+d1 < s2){
- return {s1, s2};
- }
- else if (l2+d2 > r1-d1){
- return {-1, -1};
- }
- else{
- s2 = s1 - d2;
- s2 = max(l2, s2);
- if (s2+d2 >= s1){
- s1 = s2 + d2;
- s1 = min(s1, r1);
- }
- if (s2+d2 <= s1){
- return {s1, s2};
- }
- else return {-1, -1};
- }
- }
- int main() {
- iostream::sync_with_stdio(false); cout.tie(0); cin.tie(0);
- int q; cin >> q;
- while(q--){
- int l1, l2, r1, r2;
- cin >> l1 >> r1 >> l2 >> r2;
- int s1, s2, d1, d2;
- cin >> s1 >> d1 >> s2 >> d2;
- pair<int, int> p1 = f1(l1, l2, r1, r2, s1, s2, d1, d2), p2 = f2(l1,l2, r1, r2, s1, s2, d1, d2);
- if (p1.first == -1 && p2.first == -1) cout << -1 << ' ' << -1 << '\n';
- else{
- if (p1.first == -1){
- cout << p2.first << ' ' << p2.second << '\n';
- }
- else if (p2.first == -1){
- cout << p1.first << ' ' << p1.second << '\n';
- }
- else{
- if (abs(s1 - p1.first) + abs(s2 - p1.second) < abs(s1-p2.first) + abs(s2-p2.second)){
- cout << p1.first << ' ' << p1.second << '\n';
- }
- else cout << p2.first << ' ' << p2.second << '\n';
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement