Skip to content

Commit 0c3ea25

Browse files
authored
Create Solution1.cpp
added solution to day001q001.
1 parent 1ed8e19 commit 0c3ea25

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// submission link
2+
// https://codeforces.com/contest/1560/submission/355180160
3+
4+
// Space Complexity = O(1)
5+
// 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+
using namespace std;
26+
int main(){
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 ){
33+
cout<<-1<<"\n";
34+
}
35+
else {
36+
int k = 2*(abs(b-a)-1) + 2;
37+
if(c<=k/2) cout<<c+k/2 <<"\n";
38+
else cout<<c-k/2<<"\n";
39+
}
40+
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)