Milly and balloons
Practice
3.5 (97 votes)
Implementation
Ready
Approved
Easy
Problem
57% Success 1749 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Milly and her friends are playing a game in which there is a straight rope that is fitted from both the sides between two walls. Now say leftmost endpoint is at 0-th coordinate and rightmost is at M-th coordinate. According to this game, every player Pi will attach balloons at each index in their particular segment [Li, Ri]. But the problem is that one part of any segment can belong to multiple players. Milly wants to know the number of indexes in her assigned segment that are disjoint to any other's segment.
Note : Starting (0) and ending (M) indexes of the rope can be used if comes in any of the segment.
Input
- First line will contain T (No. of test cases).
- For every test case, first line will contain four space separated integers : N (No. of friends), M(ending coordinate of the rope), A (starting coordinate of Milly's segment) and B(ending coordinate of Milly's segment).
- Next each N lines will contain two space separated integers denoting Li and Ri of ith friend.
Output
- For every test case, print the required answer in a new line.
Constraints
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 102
- 0 ≤ M ≤ 103
- 0 ≤ A, B, Li and Ri ≤ M
- A ≤ B and Li ≤ Ri
Submissions
Please login to view your submissions
Similar Problems
Points:20
14 votes
Tags:
ApprovedEasyMathOpen
Points:50
6 votes
Tags:
AlgorithmsApprovedHardMathOpen
Points:30
50 votes
Tags:
ApprovedData StructuresEasyOpenSegment TreesTrees
Editorial