File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Coldesy Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // https://codeforces.com/contest/1560/submission/355205808
2+ // time complexity:O(t)
3+ // space complexity:O(1)
4+ #include < iostream>
5+ using namespace std ;
6+
7+ int main ()
8+ {
9+ int t;
10+ cin>>t;
11+ while (t--){
12+ int a,b,c;
13+ cin>>a>>b>>c;
14+ int len;
15+ if (a>b){
16+ len=a-b;
17+ len=2 *len;
18+ } // staring at opposite end means both of them divide the circle
19+ // in exact half so we substract them and multiply by 2 to get exact length
20+ else {
21+
22+ len=b-a;
23+ len=2 *len;
24+
25+ }
26+ if (a<=len&&b<=len&&c<=len){// a,b,c ofcourse cannot be greater than length
27+ if (c+(len/2 )>len){
28+ cout<<c-(len/2 )<<endl;// c will either stare at +n/2 or -n/2
29+ }
30+ else {
31+ cout<<c+(len/2 )<<endl;
32+ }
33+ }
34+ else {cout<<-1 <<endl;}
35+ }
36+
37+ return 0 ;
38+ }
You can’t perform that action at this time.
0 commit comments