You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Time Complexity = O(1) for main solution code O(t) for overall code
6
+
7
+
8
+
9
+
// The if condition checks if the circle is valid and if the inputs exist within that circle.
10
+
// abs(b-a)<=1: Ensures a and b are not adjacent or the same.
11
+
// 2*(abs(b-a)-1)+2 < c || 2*(abs(b-a)-1)+2 < a || 2*(abs(b-a)-1)+2 < b. checks that the input numbers a, b, and c are not larger than the total size of the circle.
12
+
// If any of these are true, it prints -1 .
13
+
14
+
// The line int k = 2*(abs(b-a)-1) + 2 calculates the total number of items in the circle.
15
+
16
+
// If the inputs are valid, it calculates the number opposite to c.
17
+
// The halfway distance is k / 2.
18
+
// If c is in the first half (c<= k/2), the opposite is c + k/2.
19
+
// If c is in the second half (c > k/2), the opposite is c - k/2.
20
+
21
+
22
+
23
+
24
+
#include<bits/stdc++.h>
25
+
usingnamespacestd;
26
+
intmain(){
27
+
int t;
28
+
cin>>t;
29
+
while(t--){
30
+
int a,b,c;
31
+
cin>>a>>b>>c;
32
+
if(abs(b-a)<=1 || 2*(abs(b-a)-1)+2 < c || 2*(abs(b-a)-1)+2 < a || 2*(abs(b-a)-1)+2 < b ){
0 commit comments