Advertisement
OIQ

chin_chopa

OIQ
Dec 15th, 2019
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None
  1. #include <iostream>
  2.  
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. int a, b, n, m;
  10.  
  11. cin >> a >> b >> n >> m;
  12.  
  13. int mina = (n - 1) * a + n;
  14. int maxa = (n + 1) * a + n;
  15.  
  16. int minb = (m - 1) * b + m;
  17. int maxb = (m + 1) * b + m;
  18.  
  19. int l = max(mina, minb);
  20. int r = min(maxa, maxb);
  21.  
  22. if (l > r)
  23. cout << -1;
  24. else
  25. cout << l << " " << r;
  26.  
  27. return 0;
  28. }
Advertisement
RAW Paste Data Copied
Advertisement