Skip to content

Commit ee43780

Browse files
authored
Merge branch 'main' into main
2 parents 75ef5c1 + c234329 commit ee43780

3 files changed

Lines changed: 82 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)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//https://codeforces.com/submissions/paarth_arora link for submissions
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int main() {
5+
int t;
6+
cin >> t;
7+
while(t--) {
8+
long long a,b,c;
9+
cin>>a>>b>>c;
10+
if((abs(b-a))*2<max(a,max(b,c))){
11+
cout << -1 <<'\n';
12+
}
13+
14+
else if(c+(abs(b-a))>(abs(b-a)*2)){
15+
cout<<(c+(abs(b-a)))%(abs(b-a)*2)<<endl;
16+
}
17+
else{
18+
cout<<c+(abs(b-a))<<endl;
19+
}
20+
}
21+
22+
return 0;
23+
}
24+
//time complexity-o(1)
25+
//space complexity-o(1)

0 commit comments

Comments
 (0)