Skip to content

Commit c9b2e5b

Browse files
Create solution001.cpp
1 parent c3c0d42 commit c9b2e5b

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
ios::sync_with_stdio(false);
6+
cin.tie(nullptr);
7+
8+
int t;
9+
cin >> t;
10+
11+
while (t--) {
12+
long long a, b, c;
13+
cin >> a >> b >> c;
14+
15+
long long d = llabs(a - b); // distance between opposite people
16+
17+
// If distance is zero, circle can't exist
18+
if (d == 0) {
19+
cout << -1 << "\n";
20+
continue;
21+
}
22+
23+
long long n = 2 * d;
24+
25+
long long ans;
26+
if (c + d <= n)
27+
ans = c + d;
28+
else
29+
ans = c - d;
30+
31+
// Validate answer
32+
if (ans < 1 || ans > n)
33+
cout << -1 << "\n";
34+
else
35+
cout << ans << "\n";
36+
}
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)