Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

A. Meeting of Old Friends

题目连接:

http://codeforces.com/contest/714/problem/A

Description

Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.

Input

The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.

Sample Input

1 10 9 20 1

Sample Output

2

Hint

题意

给你两个区间,然后去掉k,问你相交的区间大小是多少

题解:

水题

代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long l1,r1,l2,r2,k;
    scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
    if(l2>r1||l1>r2)
    {
        cout<<"0"<<endl;
        return 0;
    }
    else
    {
        long long l=max(l1,l2);
        long long r=min(r1,r2);
        long long ans=r-l+1;
        if(k<=r&&k>=l)ans--;
        cout<<ans<<endl;
    }
}
posted @ 2016-09-15 10:54  qscqesze  阅读(459)  评论(0编辑  收藏  举报