Advertisement
Guest User

B

a guest
Jan 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. // author: Ryuuk
  2. #include<bits/stdc++.h>
  3. #define sz(a) int((a).size())
  4. #define pb push_back
  5. #define all(c) (c).begin(),(c).end()
  6. #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
  7. #define present(c,x) ((c).find(x) != (c).end())
  8. #define cpresent(c,x) (find(all(c),x) != (c).end())
  9. #define LSOne(i) (i&(-i))
  10. #define REP(i,a,b) for(int(i)=(a);(i)<(b);i++)
  11. #define BUG(x) {cout<<#x<<" = "<<x<<endl;}
  12. #define left(x) (x<<1)
  13. #define right(x) ((x>>1) +1)
  14. #define middle(s,e)(s+(e-s)/2)
  15. #define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
  16. #define CL(A,I) (memset(A,I,sizeof(A)))
  17.  
  18. static const int INF = 0x3f3f3f3f;
  19. static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
  20. static const long double epsilon = 1e-15;
  21. static const long double pi = acos((long double) -1);
  22. using namespace std;
  23. inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
  24. void read(int &number)
  25. {
  26.     bool negative = false;
  27.     register int c;
  28.     number = 0;
  29.     c = getchar();
  30.     if (c=='-')
  31.     {
  32.         negative = true;
  33.         c = getchar();
  34.     }
  35.     for (; (c>47 && c<58); c=getchar())
  36.         number = number *10 + c - 48;
  37.     if (negative)
  38.         number *= -1;
  39. }
  40.  
  41. typedef vector<int> vi;
  42. typedef vector<vi> vvi;
  43. typedef pair<int,int> ii;
  44. typedef long long ll;
  45.  
  46.  
  47. int main()
  48. {
  49.     #ifndef ONLINE_JUDGE
  50.         freopen("input.txt","r",stdin);
  51.         //freopen("output.txt","w",stdout);
  52.     #endif // ONLINE_JUDGE
  53.     init_io();
  54.     int n , pos, l ,r ;
  55.     cin>>n>>pos>>l>>r;
  56.     int a = 1, b = n ;
  57.     int res ;
  58.     if(pos>=l && pos <=r && a<l && b>r)
  59.     {
  60.         int x = min(pos-l, r-pos);
  61.         res=x+1 + r-l+1;
  62.     }
  63.     else if(pos>=l && pos <=r)
  64.     {
  65.         if(a==l && b==r)
  66.             res = 0;
  67.         else if(a==l)
  68.         {
  69.             res = r-pos +1;
  70.         }
  71.         else if(b==r)
  72.         {
  73.             res = pos-l +1;
  74.         }
  75.     }
  76.     else if(pos<l)
  77.     {
  78.         if(b>r)
  79.             res = (l-pos+1) + r-l+1;
  80.         else
  81.             res = 0;
  82.     }
  83.     else if(pos>r)
  84.     {
  85.         if(a<l)
  86.             res =(pos-r+1)+ r-l+1;
  87.         else
  88.             res = 0;
  89.     }
  90.  
  91.     cout <<res<<endl;
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement