File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Priyanshi_Giri Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ */
You can’t perform that action at this time.
0 commit comments