Skip to content

Commit 6fd56b9

Browse files
committed
solution to 1st problem
1 parent 577087e commit 6fd56b9

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
//Time: O(t)
3+
4+
//Space: O(1)
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
int main(){
9+
int t;
10+
cin >> t;
11+
while(t--){
12+
long long a, b, c;
13+
cin >> a >> b >> c;
14+
long long dist=llabs(a - b);
15+
long long n=2*dist;
16+
if(dist==0 || c>n){
17+
cout << -1 << '\n';
18+
continue;
19+
}
20+
long long half=n/2;
21+
if(c+half<=n){
22+
cout << c+half << '\n';
23+
}
24+
else{
25+
cout << c-half << '\n';
26+
27+
}
28+
}
29+
return 0;
30+
}
31+

0 commit comments

Comments
 (0)