Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void solve(){
- long long a, b, c, d;
- cin >> a >> b >> c >> d;
- if(d<b){
- cout<<"-1\n";
- return;
- }
- long long res,aa;
- aa=a+d-b;
- if(aa<c){
- cout<<"-1\n";
- return;
- }
- res=(d-b)+abs(aa-c);
- cout<<res<<"\n";
- }
- int main() {
- int t;
- cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement