|
| 1 | +/*PROBLEM STATEMENT : |
| 2 | +
|
| 3 | +There are n people standing in a circle. They are numbered from 1 to n in a clockwise order. The circle is even (i.e. n is even). |
| 4 | +
|
| 5 | +Each person is looking at the person standing exactly opposite him in the circle. |
| 6 | +
|
| 7 | +You are given three distinct integers a, b, and c. It is known that person a is looking at person b. |
| 8 | +
|
| 9 | +Determine the number of the person that person c is looking at. |
| 10 | +If there are multiple answers, print any of them. |
| 11 | +If there is no answer, print -1. |
| 12 | +
|
| 13 | +Approach : Total(i.e. n) = 2*(difference of a and b), so if any of the a,b,c is greater than total, it will return -1. Else we should return c + |a-b| or c-|a-b| (only one of them will be feasible) |
| 14 | +
|
| 15 | +Time Complexity: O(1) because we have created a formula directly. |
| 16 | +Space Complexity : O(1) because no. of inputs is fixed |
| 17 | +
|
| 18 | +Input |
| 19 | +7 |
| 20 | +6 2 4 |
| 21 | +2 3 1 |
| 22 | +2 4 10 |
| 23 | +5 3 4 |
| 24 | +1 3 2 |
| 25 | +2 5 4 |
| 26 | +4 3 2 |
| 27 | +Output |
| 28 | +8 |
| 29 | +-1 |
| 30 | +-1 |
| 31 | +-1 |
| 32 | +4 |
| 33 | +1 |
| 34 | +-1 |
| 35 | +
|
| 36 | +Submission link : https://codeforces.com/contest/1560/submission/355191015 |
| 37 | +*/ |
| 38 | + |
| 39 | +#include<bits/stdc++.h> |
| 40 | +#include<array> |
| 41 | +#include<unordered_set> |
| 42 | +using namespace std; |
| 43 | +typedef long long ll; |
| 44 | +#define int long long int |
| 45 | +#define F first |
| 46 | +#define S second |
| 47 | +#define pb push_back |
| 48 | +#define si set <int> |
| 49 | +#define vi vector <int> |
| 50 | +#define pii pair <int, int> |
| 51 | +#define vpi vector <pii> |
| 52 | +#define vpp vector <pair<int, pii>> |
| 53 | +#define mii map <int, int> |
| 54 | +#define mpi map <pii, int> |
| 55 | +#define spi set <pii> |
| 56 | +#define endl "\n" |
| 57 | +#define sz(x) ((int) x.size()) |
| 58 | +#define all(p) p.begin(), p.end() |
| 59 | +#define double long double |
| 60 | +#define que_max priority_queue <int> |
| 61 | +#define que_min priority_queue <int, vi, greater<int>> |
| 62 | +#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) |
| 63 | +#define vin(a) for(int i = 0; i< a.size();i++) cin>>a[i] |
| 64 | +#define vout(a) {for(auto x : a) cout << x << " "; cout << endl;} |
| 65 | +#define pp(a) for(auto x : a) cout << x.F << " " << x.S << endl |
| 66 | +#define print(a,x,y) {for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl} |
| 67 | + |
| 68 | +inline int power(int a, int b){int x = 1;while (b){if (b & 1) x *= a;a *= a;b >>= 1;}return x;} |
| 69 | +template <typename Arg1> |
| 70 | +void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } |
| 71 | +template <typename Arg1, typename... Args> |
| 72 | +void __f (const char* names, Arg1&& arg1, Args&&... args) |
| 73 | +{ |
| 74 | + const char* comma = strchr (names + 1, ','); |
| 75 | + cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...); |
| 76 | +} |
| 77 | + |
| 78 | +bool isPrime(int n){ if(n <= 1) return false; for(int i=2;i*i<=n;i++) if(n % i == 0) return false; return true; } |
| 79 | +ll gcd(ll a, ll b){ return b ? gcd(b, a % b) : a; } |
| 80 | +ll lcm(ll a, ll b){ return a / gcd(a,b) * b; } |
| 81 | +ll modpow(ll a, ll b, ll m){ ll r=1; while(b){ if(b&1) r=r*a%m; a=a*a%m; b>>=1;} return r; } |
| 82 | + |
| 83 | +bool getBit(ll x, int k){ return (x >> k) & 1; } |
| 84 | +ll setBit(ll x, int k){ return x | (1LL << k); } |
| 85 | +ll clearBit(ll x, int k){ return x & ~(1LL << k); } |
| 86 | +ll toggleBit(ll x, int k){ return x ^ (1LL << k); } |
| 87 | +int countBits(ll x){ return __builtin_popcountll(x); } |
| 88 | +bool isPowerOfTwo(ll x){ return x && !(x & (x - 1)); } |
| 89 | + |
| 90 | +vector<int> sieve(int n){ vector<int> p(n+1,1), primes; p[0]=p[1]=0; for(int i=2;i*i<=n;i++) if(p[i]) for(int j=i*i;j<=n;j+=i) p[j]=0; for(int i=2;i<=n;i++) if(p[i]) primes.pb(i); return primes; } |
| 91 | + |
| 92 | +const int N = 200005; |
| 93 | + |
| 94 | +void solve() { |
| 95 | + int a,b,c; |
| 96 | + cin >> a >> b >> c; |
| 97 | + |
| 98 | + int total = 2*abs(a-b); |
| 99 | + if (max(max(a,b),c)>total) |
| 100 | + { |
| 101 | + cout << -1 << endl;return; |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + int ans = ((c-abs(a-b))>0 )? c-abs(a-b) : c+ abs(a-b) ; |
| 106 | + cout << ans << endl;return; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +int32_t main() |
| 111 | +{ |
| 112 | + ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); |
| 113 | + int t = 1; |
| 114 | + cin >> t; |
| 115 | + while (t--) solve(); |
| 116 | + return 0; |
| 117 | +} |
0 commit comments