Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int a, b, c, a1, b1;
cin>>a1>>b1>>c;
a = max(a1, b1);
b = min(a1, b1);
if(a - b >= b && 2*(a - b) >= c){
if(c <= a - b){
c += (a - b);
}
else{
c -= (a - b);
}
cout<<c<<endl;
continue;
}
cout<<-1<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
7
6 2 4
2 3 1
2 4 10
5 3 4
1 3 2
2 5 4
4 3 2
6 2 4
2 3 1
2 4 10
5 3 4
1 3 2
2 5 4
4 3 2
Output
8
-1
-1
-1
4
1
-1
-1
-1
-1
4
1
-1
Demonstration
Codeforcess Solution 1560-B B. Who's Opposite? ,C++, Java, Js and Python,1560-B,Codeforcess Solution