File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* 1 to n people are standing in a circle. n is even.... a is looking at b.
2+ If given c is looking at some d person for given a,b then find that d. If such a combination
3+ of circle does not exist then print -1*/
4+
5+ // Time complexity: O(1)
6+ // Space complexity: O(1)
7+ // My submission: https://codeforces.com/contest/1560/submission/355204246
8+
9+ #include < bits/stdc++.h>
10+ using namespace std ;
11+
12+ using ll = long long ;
13+ #define all (x ) (x).begin(), (x).end()
14+
15+ const int MOD = 1e9 + 7 ; // 998244353
16+ const ll INF = 1e18 ;
17+
18+ void solve () {
19+ int a,b,c;
20+ cin>>a>>b>>c;
21+ int n=2 *abs (a-b);
22+ if (a>n || b>n ||c>n ) cout<<-1 <<endl;
23+ else {
24+ int x=c-n/2 ,y=c+n/2 ;
25+ if (x>=1 && x<=n) cout<<x<<endl;
26+ else cout<<y<<endl;
27+ }
28+ }
29+
30+ int main () {
31+ // Fast I/O
32+ ios::sync_with_stdio (false );
33+ cin.tie (nullptr );
34+
35+ int t;
36+ cin >> t;
37+ while (t--) {
38+ solve ();
39+ }
40+
41+ return 0 ;
42+ }
Original file line number Diff line number Diff line change 1+ ti = int (input ())
2+
3+ for _ in range (ti ):
4+ k ,l ,p = map (int ,input ().split ())
5+
6+ d = abs (k - l )
7+ f = 2 * d
8+
9+ if k > f or l > f or p > f :
10+ print (- 1 )
11+ else :
12+ if p + d <= f :
13+ print (p + d )
14+ else :
15+ print (p - d )
You can’t perform that action at this time.
0 commit comments