fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int a,b,k,x;
  7. cin>>a>>b>>k>>x;
  8.  
  9. int max=k+x;
  10. int min=k-x;
  11.  
  12. if(max<a)
  13. cout<<"IMPOSSIBLE";
  14. else if(max>=b && a<=min)
  15. cout<<b-min+1;
  16. else if(max<=a && max<=b)
  17. cout<<max-a+1;
  18. else if(min <=a && max>=b)
  19. cout<<b-a+1;
  20. else
  21. cout<<max-min+1;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 5300KB
stdin
25 75
10 5
stdout
IMPOSSIBLE