Skip to content

Commit 3c423d2

Browse files
authored
Merge branch 'opencodeiiita:main' into main
2 parents 600c1fc + 67e0ee4 commit 3c423d2

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)