Advertisement
Bassel_11

Untitled

Mar 18th, 2023
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. void solve(){
  7.         long long a, b, c, d;
  8.         cin >> a >> b >> c >> d;
  9.  
  10.        if(d<b){
  11.                cout<<"-1\n";
  12.                return;
  13.        }
  14.        long long res,aa;
  15.        aa=a+d-b;
  16.        if(aa<c){
  17.                cout<<"-1\n";
  18.                return;
  19.        }
  20.        res=(d-b)+abs(aa-c);
  21.        cout<<res<<"\n";
  22.        
  23.    
  24. }
  25.  
  26. int main() {
  27.     int t;
  28.     cin >> t;
  29.  
  30.     while (t--) {
  31.             solve();
  32.     }
  33.  
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement