Skip to content

Commit 7dfb447

Browse files
committed
added day1 sol1
1 parent fc1fc6f commit 7dfb447

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

  • Problems/Mathematics/Day-01/sol/Mohan
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Problem : Who's Opposite
3+
4+
Approach : n cannot be greater than 2*abs(a-b);
5+
a,b,c should also be smaler than or equal to n
6+
7+
Time complexity - O(1)
8+
Space complexity - O(1)
9+
10+
11+
Submission Link : https://codeforces.com/contest/1560/submission/355221224
12+
13+
*/
14+
#include <bits/stdc++.h>
15+
using namespace std;
16+
17+
#define fast_io ios::sync_with_stdio(false); cin.tie(nullptr);
18+
#define int long long
19+
#define ull unsigned long long
20+
#define ld long double
21+
#define vi vector<int>
22+
#define vb vector<bool>
23+
#define vs vector<string>
24+
#define pii pair<int,int>
25+
#define pll pair<long long,long long>
26+
#define vpi vector<pii>
27+
#define vpl vector<pll>
28+
#define vvi vector<vi>
29+
#define mii map<int,int>
30+
#define si set<int>
31+
#define loop(i,n) for (int i = 0; i < n; i++)
32+
#define rloop(i,n) for (int i = n - 1; i >= 0; i--)
33+
#define loop1(i,a,b) for (int i = a; i <= b; i++)
34+
#define rloop1(i,a,b) for (int i = a; i >= b; i--)
35+
#define pb push_back
36+
#define ppb pop_back
37+
#define mp make_pair
38+
#define F first
39+
#define S second
40+
#define lb lower_bound
41+
#define ub upper_bound
42+
#define all(x) (x).begin(), (x).end()
43+
#define rall(x) (x).rbegin(), (x).rend()
44+
#define sz(x) ((int)(x).size())
45+
#define endl '\n'
46+
#define printy cout<<"YES"<<endl
47+
#define printn cout<<"NO"<<endl
48+
#define vout(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; cout << endl;
49+
#define vpout(a) loop(i,sz(a)) cout <<a[i].F<<' '<< a[i].S<< endl; cout << endl;
50+
#define rt(x){ cout<<x<<endl; return; }
51+
52+
53+
void solve(){
54+
int a,b,c;
55+
cin>>a>>b>>c;
56+
int size = abs(b-a)*2;
57+
if(a>size || b>size || c>size){ rt(-1)}
58+
else cout << (c > size/2 ? c - size/2 : size/2 + c) << endl;
59+
}
60+
61+
62+
int32_t main(){
63+
fast_io;
64+
int t=1;
65+
cin>>t;
66+
while(t--){
67+
solve();
68+
}
69+
return 0;
70+
}

0 commit comments

Comments
 (0)