Skip to content

Commit 63fb220

Browse files
Merge branch 'main' into main
2 parents 75c9eb9 + 6482242 commit 63fb220

5 files changed

Lines changed: 145 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int main()
6+
{
7+
int t;
8+
cin>>t;
9+
while(t--)
10+
{
11+
int a, b, c;
12+
cin>>a>>b>>c;
13+
int half=abs(b-a);
14+
int full=2*half;
15+
// cout<<full<<endl;
16+
if(a>full || b> full || c > full)
17+
{
18+
cout<<-1<<endl;
19+
}
20+
else
21+
{
22+
int ans=c+half;
23+
if(ans>full)
24+
{
25+
ans-=full;
26+
}
27+
cout<<ans<<endl;
28+
}
29+
30+
}
31+
32+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// 1. Problem Statement -------------------------------------------------
2+
/*
3+
There are n people standing in a circle, where n is even.
4+
Each person looks at the person standing exactly opposite to them.
5+
6+
You are given three distinct integers a, b, and c.
7+
It is known that person a is looking at person b.
8+
9+
Determine the person that person c is looking at.
10+
If such a person cannot exist, print -1.
11+
*/
12+
13+
// 2. Approach -----------------------------------------------------------
14+
/*
15+
The pair (a, b) fixes the entire circle.
16+
Once the circle is fixed, every person has exactly one opposite person.
17+
18+
If person c does not fit into this fixed circle, the answer is -1.
19+
Otherwise, move half the circle from c to find the person they are looking at.
20+
*/
21+
22+
// 3. Complexity ---------------------------------------------------------
23+
/*
24+
Time Complexity: O(1) per test case
25+
Space Complexity: O(1)
26+
*/
27+
28+
//4. problem submission link-----------------------------------
29+
// https://codeforces.com/problemset/status?my=on
30+
31+
// Compiling Code in Java (Solution1.java) -------------------------------
32+
33+
import java.util.*;
34+
35+
public class Solution1 {
36+
37+
public static int findOpposite(int a, int b, int c) {
38+
int n = 2 * Math.abs(a - b);
39+
if (a > n || b > n || c > n) {
40+
return -1;
41+
}
42+
int half = n / 2;
43+
if (c + half <= n) {
44+
return c + half;
45+
}
46+
return c - half;
47+
}
48+
49+
public static void main(String[] args) {
50+
Scanner sc = new Scanner(System.in);
51+
int t = sc.nextInt();
52+
while (t-- > 0) {
53+
int a = sc.nextInt();
54+
int b = sc.nextInt();
55+
int c = sc.nextInt();
56+
System.out.println(findOpposite(a, b, c));
57+
}
58+
sc.close();
59+
}
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solve():
2+
t = int(input())
3+
for _ in range(t):
4+
a, b, c = map(int, input().split())
5+
6+
d = abs(a - b)
7+
n = 2 * d
8+
9+
10+
if n == 0 or max(a, b, c) > n:
11+
print(-1)
12+
continue
13+
14+
half = n // 2
15+
16+
if c + half <= n:
17+
print(c + half)
18+
else:
19+
print(c - half)
20+
21+
solve()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solve():
2+
t = int(input())
3+
for _ in range(t):
4+
a, b, c = map(int, input().split())
5+
6+
d = abs(a - b)
7+
n = 2 * d
8+
9+
if n == 0 or max(a, b, c) > n:
10+
print(-1)
11+
continue
12+
13+
half = n // 2
14+
15+
if c + half <= n:
16+
print(c + half)
17+
else:
18+
print(c - half)
19+
20+
# Run
21+
solve()

contributers.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
| Saurav Gitte | SauravGitte | IIIT Allahabad |
2222
| Avaneesh Verma | avaneeshk2307-wq | IIIT Allahabad |
2323
| Aditya Shirsatrao | adityashirsatrao007 | N. K. Orchid College Of Engineering & Technology, Solapur |
24+
| Sourish Awasthi | LooninS | IIIT Allahabad |
25+
| Ishan Tripathi | ishantripathi64 | IIIT Allahabad |
26+
| Lavay Garg | lavaygarg | IIIT Allahabad |
27+
| Kushagra Sahu | KushagraSahu-01 | IIIT Allahabad |
2428
| Sourish Awasthi | LooninS | IIIT Allahabad |
2529
| Ishan Tripathi | ishantripathi64 | IIIT Allahabad |
2630
| Lavay Garg | lavaygarg | IIIT Allahabad |
2731
| Aditi Guin |GuinAditi |KIIT
32+
| Himanshu Vitthalani | Himanshu-1903 | IIIT Allahabad
33+
| Abhishek Tripathi | Astinel-prime | IIIT Allahabd |
34+
| Ibrahim Raza Beg | PHOX-9 | IIIT Allahabd |
35+
| Vaishali ojha | Nomen06 | IIIT Allahabd |
36+
| Siddhant Shekhar | sshekhar563 | United University |
37+
| Ayush Saha | verifiedHuman18 | IIIT Allahabad |
38+
2839
<!-- ADD ABOVE THIS -->
2940
<!-- example | Korvac | Betty | Reyansh College | -->

0 commit comments

Comments
 (0)