Skip to content

Commit 8f5a345

Browse files
authored
Merge pull request #128 from ViMo018/main
Added solution.cpp
2 parents 6155608 + 0d28cdb commit 8f5a345

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include<bits/stdc++.h>
2+
#include<queue>
3+
using namespace std;
4+
typedef unordered_map<int, int> umii;
5+
typedef unordered_map<long long, long long> umll;
6+
typedef unordered_map<char, long long> umci;
7+
typedef vector<pair<int, int>> vpi;
8+
typedef vector<int> vi;
9+
typedef long long ll;
10+
typedef vector<long long> vll;
11+
typedef unordered_map<int , bool> umib;
12+
#define sum(v) accumulate(v.begin(), v.end(), 0)
13+
#define endl '\n'
14+
#define f0(i, n) for(long long i = 0; i < n; i++)
15+
#define f1(i, n) for(long long i = 1; i < n; i++)
16+
#define as(v) sort(v.begin(), v.end())
17+
#define all(x) (x).begin(), (x).end()
18+
#define pb push_back
19+
template<class T> umll frequency(vector<T> &v) {umll freq;for(auto &x:v) freq[x]++; return freq;}
20+
template<class T> umci S_frequency(vector<T> &v) {umci freq;for(auto &x:v) freq[x]++; return freq;}
21+
template <class T> void input(vector<T> &v){for(auto &x:v)cin>>x;}
22+
ll power(ll x, ll y){ ll res = 1; while (y > 0){ if (y & 1) res = (ll)(res*x); y = y>>1; x = (ll)(x*x); } return res; }
23+
void pvll(const vector<long long> &arr){for(auto it : arr){cout << it << " ";}cout << endl;}
24+
void pvi(const vector<int> &arr){for(auto it : arr){cout << it << " ";}cout << endl;}
25+
26+
27+
void solve(){
28+
29+
//-------------INPUT-------------
30+
ll a;
31+
cin >> a;
32+
ll b,c;
33+
cin >> b >> c;
34+
if(b<a)
35+
{
36+
swap(a,b);
37+
}
38+
// n is total number
39+
ll n = 2*(b-a);
40+
//cout << n << " ";
41+
if(a>n || b>n || c>n)
42+
{
43+
// this states that given constraints are not forming a proper circle
44+
cout << -1 << endl;
45+
return;
46+
}
47+
48+
if(c-n/2 != a && c-n/2 != b)
49+
{
50+
if(c-n/2 <=n && c-n/2>=1)
51+
{
52+
53+
// looking exactly opposite of the c if c-n/2 meetss the condition
54+
cout << c - n/2 << endl;
55+
56+
return;
57+
}
58+
}
59+
60+
61+
if(c+n/2 != a && c+n/2 != b)
62+
{
63+
64+
if(c+n/2 <=n && c+n/2>=1)
65+
{
66+
// looking exactly opposite of the c if c+n/2 meets the condition
67+
cout << c + n/2 << endl;
68+
69+
return;
70+
}
71+
}
72+
73+
74+
cout << -1 << endl;
75+
76+
77+
//-------------CODE--------------
78+
79+
80+
81+
}
82+
83+
84+
int main(){
85+
int tt; cin >> tt; while(tt--)
86+
{solve();};
87+
}
88+
89+
90+
// SUBMISSION LINK
91+
//https://codeforces.com/contest/1560/submission/355199870

0 commit comments

Comments
 (0)