#P9953. [USACO20OPEN] Social Distancing II B
[USACO20OPEN] Social Distancing II B
Problem Description
Due to the outbreak of the highly contagious cow disease COWVID-19, Farmer John is very worried about the health of his cows.
Even though he has tried his best to make his cows () practice “social distancing”, many cows have unfortunately become infected.
The cows numbered are located at distinct positions along a long straight road (equivalent to a one-dimensional number line). Cow is at position . Farmer John knows that there exists a radius such that any cow within a distance of at most units from an infected cow will also become infected (and then it will infect cows within units of it, and so on).
Unfortunately, Farmer John does not know the exact value of . He only knows which of his cows are infected. Given this information, find the minimum number of cows that were infected initially.
Input Format
The first line contains . The next lines each contain two integers and describing a cow, where is its position (), and is for a healthy cow and for an infected cow. Also, all cows that could possibly be infected through the spread have already been infected.
Output Format
Output the minimum number of cows that were already infected before the disease started spreading.
6
7 1
1 1
15 1
3 1
10 0
6 1
3
Hint
Sample Explanation 1
In this example, we know that , otherwise the cow at position would infect the cow at position . Therefore, at least cows were infected initially: one of the two cows at positions and , one of the two cows at positions and , and the cow at position .
Translated by ChatGPT 5