#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 NN cows (1N10001\le N\le 1000) practice “social distancing”, many cows have unfortunately become infected.

The cows numbered 1N1\ldots N are located at distinct positions along a long straight road (equivalent to a one-dimensional number line). Cow ii is at position xix_i. Farmer John knows that there exists a radius RR such that any cow within a distance of at most RR units from an infected cow will also become infected (and then it will infect cows within RR units of it, and so on).

Unfortunately, Farmer John does not know the exact value of RR. 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 NN. The next NN lines each contain two integers xx and ss describing a cow, where xx is its position (0x1060\le x\le 10^6), and ss is 00 for a healthy cow and 11 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 R<3R<3, otherwise the cow at position 77 would infect the cow at position 1010. Therefore, at least 33 cows were infected initially: one of the two cows at positions 11 and 33, one of the two cows at positions 66 and 77, and the cow at position 1515.

Translated by ChatGPT 5