|
| 1 | + |
| 2 | +// **************** Author : Tashin.Parvez *************************\ |
| 3 | +// **************** Updated: 21-06-23 *************************\ |
| 4 | +
|
| 5 | +#include <bits/stdc++.h> |
| 6 | +#define faster \ |
| 7 | + ios_base::sync_with_stdio(false); \ |
| 8 | + cin.tie(0); \ |
| 9 | + cout.tie(0); |
| 10 | +#define Read(x) freopen(x, "r", stdin) |
| 11 | +#define Write(x) freopen(x, "w", stdout) |
| 12 | +#define CRACKED return 0; |
| 13 | +#define nl "\n" |
| 14 | + |
| 15 | +// data_type_compressions : |
| 16 | +#define int long long |
| 17 | +#define ull unsigned long long |
| 18 | +#define ld long double |
| 19 | + |
| 20 | +#define PI 3.14159265358979323846 |
| 21 | + |
| 22 | +// I/O : |
| 23 | +#define loop(n) for (int i = 0; i < n; i++) // 0 to n Input or Output |
| 24 | +#define output(x) cout << x << nl // out |
| 25 | +#define printarray(arr, len) \ |
| 26 | + for (int i = 0; i < len; i++) \ |
| 27 | + { \ |
| 28 | + cout << arr[i] << " "; \ |
| 29 | + if (i + 1 == len) \ |
| 30 | + cout << endl; \ |
| 31 | + } // array print |
| 32 | + |
| 33 | +#define sq(x) ((x) * (x)) // x^2 square |
| 34 | +#define len(s) s.length() |
| 35 | +#define setDec(x) fixed << setprecision(x) |
| 36 | + |
| 37 | +#define YES printf("YES\n") |
| 38 | +#define Yes printf("Yes\n") |
| 39 | +#define NO printf("NO\n") |
| 40 | +#define No printf("No\n") |
| 41 | + |
| 42 | +using namespace std; |
| 43 | + |
| 44 | +/* |
| 45 | + int n; cin>>n; |
| 46 | + int arr[n]; |
| 47 | + for(auto &v : arr) cin>>v; |
| 48 | +
|
| 49 | +
|
| 50 | + if(!(i&1)) //-------------- EVEN (for even --->> i&1 == 0) |
| 51 | + cout<<i<<nl; |
| 52 | +
|
| 53 | +*/ |
| 54 | + |
| 55 | +void solution() |
| 56 | +{ |
| 57 | + int i, j, k, l, m, n, a, b, c, d, w, x, y, z, t, count = 0, index; |
| 58 | + string s; |
| 59 | + bool flag = false; |
| 60 | + |
| 61 | + cin >> a >> b >> c; |
| 62 | + int temp = a + b; |
| 63 | + |
| 64 | + b = max(a, b); |
| 65 | + a = temp - b; |
| 66 | + x = b - a; |
| 67 | + |
| 68 | + // cout << "ADD " << x; |
| 69 | + int higg = b + x - a; |
| 70 | + if ((higg) % 2 != 0 || b > higg || a > higg) |
| 71 | + { |
| 72 | + cout << -1 << nl; |
| 73 | + return; |
| 74 | + } |
| 75 | + // cout << "HIGGEST " << higg << nl; |
| 76 | + if (c > a && c < b) |
| 77 | + { |
| 78 | + // cout << "TASHIN " << nl; |
| 79 | + int ans = c + x; |
| 80 | + if (ans > higg) |
| 81 | + { |
| 82 | + |
| 83 | + if (ans - higg >= 1 && a > ans - higg) |
| 84 | + cout << ans - higg << nl; |
| 85 | + else |
| 86 | + cout << -1 << nl; |
| 87 | + } |
| 88 | + else if (b + x >= ans && b < ans) |
| 89 | + { |
| 90 | + // cout << c << nl; |
| 91 | + cout << ans << nl; |
| 92 | + } |
| 93 | + |
| 94 | + else |
| 95 | + cout << -1 << nl; |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + // cout << "TASHIN " << nl; |
| 100 | + if (c > higg) |
| 101 | + { |
| 102 | + cout << -1 << nl; |
| 103 | + return; |
| 104 | + } |
| 105 | + else if (c > b) |
| 106 | + { |
| 107 | + int ans = c - x; |
| 108 | + if (ans != b && ans != a) |
| 109 | + cout << ans << nl; |
| 110 | + else |
| 111 | + cout << -1 << nl; |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + // c < A |
| 116 | + int ans = c + x; |
| 117 | + if (ans != b && ans != a && ans > a && ans < b) |
| 118 | + cout << ans << nl; |
| 119 | + else |
| 120 | + cout << -1 << nl; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +int32_t main() |
| 126 | +{ |
| 127 | + faster; |
| 128 | + |
| 129 | + // #ifdef TashinParvez |
| 130 | + // Read("input.txt"); |
| 131 | + // // Write("output.txt"); |
| 132 | + // #endif // TashinParvez |
| 133 | + |
| 134 | + int t = 1; |
| 135 | + cin >> t; |
| 136 | + int c = 1; |
| 137 | + |
| 138 | + while (t--) |
| 139 | + { |
| 140 | + // cout << "Case " << c++ << ": "; |
| 141 | + solution(); |
| 142 | + } |
| 143 | + |
| 144 | + CRACKED; |
| 145 | +} |
0 commit comments