Two covers
InterviewTime limit3sMemory limit1024 MB
Count positions x that lack both a piece reaching k letters left of x and a different piece reaching k letters right of x.
- Level
Medium4 of 10
- Topics
- Array, Prefix sum, Sorting
- Solved
- No attempts yet
Statement
In a typical genome assembly problem, we are given a set of small strings called pieces, and our task is to find a superstring of them with some reasonable properties. In this problem, you are given one such superstring and a collection of pieces aligned to it. Your task is to evaluate one particular property.
You are given the length of the superstring ℓ, a list of pieces, and a number . The positions in the superstring are numbered from 1 to . For each piece , you are given the positions of its beginning and end.
The letter at position in the superstring is well-covered if:
- There is a piece such that and .
- There is a different piece such that and .
Your task is to count the number of letters which are not well-covered.
Input
The first line contains an integer , the number of test cases. Each test case is preceded by a blank line.
Each test case starts with a line containing three integers , , and . Each of the following lines contains two integers and (), the endpoints of a piece. The pairs are all distinct.
Output
For each test case, output a single line with a single integer: the number of letters that are not well-covered.
Hint
The well-covered letters are at positions 3, 4, and 5. The letter at position 6 is not well-covered.