Skip to content

Commit f11f079

Browse files
Merge pull request #175 from hellopaintinghi-cmd/priyanshi-giri
Day 01 Mathematics: Question 1 Solution
2 parents 43a9075 + 32db5e3 commit f11f079

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
ios_base::sync_with_stdio(false);
6+
cin.tie(NULL);
7+
8+
int t;
9+
cin >> t;
10+
while (t--) {
11+
int a, b, c;
12+
cin >> a >> b >> c;
13+
int n = 2*(abs(a-b));
14+
15+
if(a == b){
16+
cout << -1 << endl;
17+
continue;
18+
}
19+
20+
if(a > n || b > n || c > n){
21+
cout << -1 << endl;
22+
continue;
23+
}
24+
25+
if(c + (n/2) <= n){
26+
cout << (c+(n/2)) << endl;
27+
}else{
28+
cout << (c-(n/2)) << endl;
29+
}
30+
31+
}
32+
return 0;
33+
}
34+
35+
36+
37+
38+
/* Explaination : The opposite numbers must be having exactly n/2 numbers in between, hence the total number, ie. n = 2*abs(a-b).
39+
40+
Time Complexity : O(t), t is the number of test cases.
41+
42+
Submission Link : https://codeforces.com/contest/1560/submission/355247479
43+
44+
*/

0 commit comments

Comments
 (0)