302088: CF397A. On Segment's Own Points
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
On Segment's Own Points
题意翻译
给定一个区间[0,100],给定n个线段[$l_i,r_i$],求第一个线段中有多少个单位长度没有被其他线段覆盖。题目描述
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a $ 100 $ centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate $ 0 $ , and the opposite end has coordinate $ 100 $ . Overall, the university has $ n $ students. Dean's office allows $ i $ -th student to use the segment $ (l_{i},r_{i}) $ of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others $ (n-1) $ students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.输入输出格式
输入格式
The first line contains a positive integer $ n $ ( $ 1<=n<=100 $ ). The $ (i+1) $ -th line contains integers $ l_{i} $ and $ r_{i} $ ( $ 0<=l_{i}<r_{i}<=100 $ ) — the endpoints of the corresponding segment for the $ i $ -th student.
输出格式
On a single line print a single number $ k $ , equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
输入输出样例
输入样例 #1
3
0 5
2 8
1 6
输出样例 #1
1
输入样例 #2
3
0 10
1 5
7 15
输出样例 #2
3