fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. int a, b, c, n;
  9. cin >> a >> b >> c >> n;
  10. int x = (a - c) + (b - c) + c;
  11. int p = n - x;
  12. if(p <= 0 or x < 0 or a < c or b < c) {
  13. cout << "-1" << "\n";
  14. return 0;
  15. }
  16. cout << p << "\n";
  17. return 0;
  18. }
Success #stdin #stdout 0s 4388KB
stdin
0 0 0 0
stdout
-1