fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static Long min(Long a,Long b){
  11. return ((a)<(b)?(a):(b));
  12. }
  13. public static Long max(Long a,Long b){
  14. return ((a)>(b)?(a):(b));
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. Long s1=6L,e1=23L,s2=2L,e2=17L,ans=0L;
  19. //s1 and e1 are for 1st interval,
  20. //s2 and e2 are for 2nd interval,
  21. //ans is required ans
  22. Boolean broken1,broken2;
  23. broken1=(s1<=e1)?false:true;
  24. broken2=(s2<=e2)?false:true;
  25. if(broken1){
  26. if(broken2)
  27. ans=min(e1,e2)+1 + 23-max(s1,s2)+1;
  28. else{
  29. if(e1>=s2) ans+=(min(e1,e2)-s2+1);
  30. if(s1<=e2) ans+=(e2-max(s1,s2)+1);
  31. }
  32. }
  33. else{
  34. if(broken2){
  35. if(e2>=s1) ans+=(min(e1,e2)-s1+1);
  36. if(s2<=e1) ans+=(e1-max(s1,s2)+1);
  37. }
  38. else{
  39. if(e1<s2 || e2<s1) ans=0L;
  40. else ans=min(e1,e2)-max(s1,s2)+1;
  41. }
  42. }
  43. System.out.println(ans+"");
  44. }
  45. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
12