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 ;
}

CodeForces 714A的更多相关文章

  1. Codeforces 714A Meeting of Old Friends

    A. Meeting of Old Friends time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  2. Codeforces 714A 朋友聚会

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395268.html A. Meeting of Old Friends time limit p ...

  3. 2018SDIBT_国庆个人第六场

    A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...

  4. CSUST 8.5 早训

    ## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. Beta版本发布140字评论

    1.飞天小女警组: 礼物挑选工具:系统界面十分新颖,相比于前阶段,增加了账号登陆的功能,并且还根据不同的价位区间添加了礼物的图片,并根据礼物的受欢迎程度添加了top10的功能,并且增加了关于本网站的问 ...

  2. Nmap用法实例

    <给Linux系统/网络管理员的nmap的29个实用例子> https://linux.cn/article-2561-1.html

  3. [转帖]DAS、SAN、NAS

    http://blog.itpub.net/26736162/viewspace-2214368/ DAS(Direct-attached Storage) 直连存储 直连式存储与服务器主机之间的连接 ...

  4. 使用Shell脚本删除/清空日志文件

    话不多少,直接上代码: #!/bin/bash workdir=("/home/Tax_Punish_Ret/log_txt") #可填写多个路径, 用空格隔开 # 查找日志文件 ...

  5. File FileStream StreamReader StreamWriter C#

    存在各种各样的IO设备,比如说文件File类(字符串文件和二进制文件),可以直接使用File类对文件进行读写操作. 这些各种IO的读取和写入是通过流的形式实现的,基类为Stream,针对各种不同的IO ...

  6. 关于#pragma comment

    #pragma comment(lib,"ws2_32.lib") #pragma comment(lib,"ws2_32.lib")表示连接Ws2_32.li ...

  7. LeetCode 717. 1-bit and 2-bit Characters

    We have two special characters. The first character can be represented by one bit 0. The second char ...

  8. 一些基于jQuery开发的控件

    基于jQuery开发,非常简单的水平方向折叠控件.主页:http://letmehaveblog.blogspot.com/2007/10/haccordion-simple-horizontal-a ...

  9. 前端基础:HTTP 状态码详解

    HTTP 状态码详解 1xx(信息类):表示接收到请求并继续处理 100 客户端应当继续发送请求.这个临时响应是用来通知客户端他的部分请求已经被服务器接收,且仍未被拒绝.客户端应当继续发送请求的剩余部 ...

  10. hdu 5638 Toposort (拓扑排序+线段树)

    Toposort Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...