-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2035A.cpp
More file actions
30 lines (22 loc) · 836 Bytes
/
2035A.cpp
File metadata and controls
30 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t; // Number of test cases
while (t--) {
ll n, m, r, c;
cin >> n >> m >> r >> c;
// Calculate Manhattan distances to each corner
ll distance1 = abs(r - 1) + abs(c - 1); // Top-left corner
ll distance2 = abs(r - 1) + abs(c - m); // Top-right corner
ll distance3 = abs(r - n) + abs(c - 1); // Bottom-left corner
ll distance4 = abs(r - n) + abs(c - m); // Bottom-right corner
// The result is the maximum distance to any of the corners
ll totalDistance = max({distance1, distance2, distance3, distance4});
cout << totalDistance << '\n';
}
return 0;
}