Codeforces Round #371 (Div. 2) Meeting of Old Friends
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
LL l1, r1, l2, r2, k , l , r , ans=0;
while(~sf("%I64d %I64d %I64d %I64d %I64d", &l1, &r1, &l2, &r2, &k))
{
if(l1 > l2) l = l1;
else l = l2;
if(r1 > r2) r = r2;
else r = r1;
if(k >= l and k <= r)
{
//pf("%I64d\n", ((k-1 - l)+1) + ((r - k-1) + 1 ));
ans = ((k-1 - l)+1) + ((r - k-1) + 1 );
}
else
{
//pf("%I64d\n", r - l + 1);
ans = r - l + 1;
}
if(ans <= 0) pf("0\n");
else pf("%I64d\n", ans);
}
return 0;
}
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
LL l1, r1, l2, r2, k , l , r , ans=0;
while(~sf("%I64d %I64d %I64d %I64d %I64d", &l1, &r1, &l2, &r2, &k))
{
if(l1 > l2) l = l1;
else l = l2;
if(r1 > r2) r = r2;
else r = r1;
if(k >= l and k <= r)
{
//pf("%I64d\n", ((k-1 - l)+1) + ((r - k-1) + 1 ));
ans = ((k-1 - l)+1) + ((r - k-1) + 1 );
}
else
{
//pf("%I64d\n", r - l + 1);
ans = r - l + 1;
}
if(ans <= 0) pf("0\n");
else pf("%I64d\n", ans);
}
return 0;
}
Comments
Post a Comment