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 l1r1l2r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018l1 ≤ r1l2 ≤ 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

Input
1 10 9 20 1
Output
2
Input
1 100 50 200 75
Output
50

Hint

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.

算是一道非常非常简单的贪心做法题吧。

但我还是WA了无数发,只因为那个被我犯过好几次的错误,不是第一次犯这种错了。

只考虑到了两个区间相交和相离的情况,没有考虑到内含的情况。

这题应该注意的是k是在相交区间断点的问题。

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
typedef long long LL; struct con{
LL head;
LL tail;
}con[];
LL cmp(struct con a,struct con b)
{
if(a.head==b.head)
return a.tail<b.tail;
return a.head<b.head;
}
int main()
{
LL i,p,j,n;
LL k,ans=;
// scanf("%lld",&p);
// printf("%lld\n",p);
for(i=;i<=;i++)
{
scanf("%lld%lld",&con[i].head,&con[i].tail);
}
scanf("%lld",&k);
sort(con,con+,cmp); if(con[].head<=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].head<=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
if(con[].tail>=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].tail>=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
printf("%lld\n",ans);
return ;
}

最新文章

  1. No.023:Merge k Sorted Lists
  2. linux Centos下安装 sqlserver
  3. Theano2.1.10-基础知识之循环
  4. INSTALL_FAILED_INSUFFICIENT_STORAGE
  5. 在excel批量更改单元格类型后的批量刷新显示
  6. CSS3实战手册(第3版)(影印版)
  7. 0到N数其中三个数的全排列
  8. Mina的线程模型
  9. 【linux操作命令】crontab
  10. codeforces 几道题目
  11. 轻松学会ES6新特性之生成器
  12. Recurrent Neural Networks(RNN) 循环神经网络初探
  13. 扩展crt
  14. Layout-3相关代码:3列布局代码演化[二]
  15. 数据量你造吗-JAVA分页
  16. DOM表单(复选框)
  17. C# 生成一个带数字的饼图
  18. linux下安装pycharm
  19. 压测freeswitch--安装sipp
  20. linux 安装 nvm

热门文章

  1. JMeter性能测试基础 (3) - 使用参数文件做搜索引擎性能对比
  2. Pygame - Python游戏编程入门(0) 转
  3. [转帖]华为Hi 1620 等ARM 服务器版本CPU信息.
  4. jQuery : 有关TypeError: invalid ‘in’ operand obj的错误
  5. JavaScript 稀奇的js语法
  6. 使用 MQTTnet 快速实现 MQTT 通信
  7. C语言版kafka消费者代码运行时异常kafka receive failed disconnected
  8. 【Java并发编程】之十一:线程间通信中notify通知的遗漏
  9. Android 资源目录 相关知识 raw、 drawable、 values..
  10. Python之旅:并发编程之IO模型