Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // author: Ryuuk
- #include<bits/stdc++.h>
- #define sz(a) int((a).size())
- #define pb push_back
- #define all(c) (c).begin(),(c).end()
- #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
- #define present(c,x) ((c).find(x) != (c).end())
- #define cpresent(c,x) (find(all(c),x) != (c).end())
- #define LSOne(i) (i&(-i))
- #define REP(i,a,b) for(int(i)=(a);(i)<(b);i++)
- #define BUG(x) {cout<<#x<<" = "<<x<<endl;}
- #define left(x) (x<<1)
- #define right(x) ((x>>1) +1)
- #define middle(s,e)(s+(e-s)/2)
- #define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
- #define CL(A,I) (memset(A,I,sizeof(A)))
- static const int INF = 0x3f3f3f3f;
- static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
- static const long double epsilon = 1e-15;
- static const long double pi = acos((long double) -1);
- using namespace std;
- inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
- void read(int &number)
- {
- bool negative = false;
- register int c;
- number = 0;
- c = getchar();
- if (c=='-')
- {
- negative = true;
- c = getchar();
- }
- for (; (c>47 && c<58); c=getchar())
- number = number *10 + c - 48;
- if (negative)
- number *= -1;
- }
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef pair<int,int> ii;
- typedef long long ll;
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- #endif // ONLINE_JUDGE
- init_io();
- int n , pos, l ,r ;
- cin>>n>>pos>>l>>r;
- int a = 1, b = n ;
- int res ;
- if(pos>=l && pos <=r && a<l && b>r)
- {
- int x = min(pos-l, r-pos);
- res=x+1 + r-l+1;
- }
- else if(pos>=l && pos <=r)
- {
- if(a==l && b==r)
- res = 0;
- else if(a==l)
- {
- res = r-pos +1;
- }
- else if(b==r)
- {
- res = pos-l +1;
- }
- }
- else if(pos<l)
- {
- if(b>r)
- res = (l-pos+1) + r-l+1;
- else
- res = 0;
- }
- else if(pos>r)
- {
- if(a<l)
- res =(pos-r+1)+ r-l+1;
- else
- res = 0;
- }
- cout <<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement