Skip to content

Commit a1276cd

Browse files
authored
Merge pull request #177 from d2-e2-v2/main
added Q1 solution.
2 parents ff89d41 + cfefdd5 commit a1276cd

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

  • Problems/Mathematics/Day-01/sol/Abhay
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
/*
4+
Logic:
5+
The main key in solving the problem is that a,b will be enought to know that the size of the area.
6+
Another observation would be that 1 is always facing the element more than the element which faces
7+
at the last element or the size of the circle.
8+
Once, you get the size of the array, we just have to check if the any of the elements are larger than
9+
the size of the array.
10+
On deeper checks like- a=3, b=2,c=1;
11+
we can observe how this isn't true but how does the conditon fulfill the case?
12+
--> the max check covers all small checks, like the circle don being possible
13+
in cases like a=1,b=6, c=100
14+
--> the circle condition is also checked by the max case.
15+
16+
So, after the checking, we need to see the answer, that can be easily given as the
17+
difference is same for all pairs of elements modular nature of the circle( cool words that make sense)
18+
19+
Time complexity-->
20+
21+
The time complexity is O(1)
22+
The space complexity is O(1)
23+
24+
Submission link- https://codeforces.com/contest/1560/submission/355188467
25+
*/
26+
//Soln->
27+
int main() {
28+
ios::sync_with_stdio(false);
29+
cin.tie(nullptr);
30+
31+
int t;
32+
cin >> t;
33+
34+
while (t--) {
35+
int a,b,c;
36+
cin>>a;
37+
cin>>b;
38+
cin>>c;
39+
int x=abs(b-a);
40+
if(max({a,b,c})>(2*x))
41+
cout<<-1<<endl;
42+
else
43+
{
44+
if(c>x)
45+
cout<<c-x<<endl;
46+
else
47+
cout<<c+x<<endl;
48+
}
49+
50+
}
51+
return 0;
52+
}
53+

0 commit comments

Comments
 (0)