Skip to content

Commit 7be3373

Browse files
authored
Add Coldesy.cpp for Codeforces problem 1560
Implement Coldesy problem solution from Codeforces.
1 parent f11f079 commit 7be3373

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)