An Animal Contest 1 P6 - Alpaca Distancing

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 0.5s
Java 1.5s
Python 1.5s
Memory limit: 256M

Authors:
Problem types

William the Alpaca is arranging a socially-distanced party with N potential invitees. He would like to invite all of them, but alpacas are picky and they each have their own requirements. First, each alpaca demands to stand at a position ai, occupying a point on a straight line. On top of that, due to the rise of a contagious disease, each alpaca has a range of bi, meaning they won't tolerate another alpaca being strictly less than bi units from their position. William wants to invite as many alpacas as possible, such that each invited alpaca satisfies the range requirement of every other invited alpaca. Help William find the maximum number of alpacas he can invite!

Constraints

1N105

1ai,bi109

Subtask 1 [10%]

1N8

1ai,bi20

Subtask 2 [10%]

1N2103

1ai,bi106

Subtask 3 [50%]

1ai,bi106

Subtask 4 [30%]

No additional constraints.

Input Specification

The first line contains one integer N.

The next N lines contain ai and bi for the ith alpaca.

Output Specification

Output one integer, representing the maximum amount of friends William will be able to invite.

Sample Input 1

Copy
5
4 2
14 4
7 5
3 3
13 1

Sample Output 1

Copy
2

Explanation for Sample 1

Alpaca 1 and alpaca 5 can be chosen. Alpaca 1's range reaches 4+2=6 and alpaca 5's range reaches 131=12, so they are out of each other's ranges. Hence, this is valid, and it can be shown that this is one of the optimal arrangements.

Sample Input 2

Copy
7
19 3
4 8
6 5
20 13
14 4
13 7
1 4

Sample Output 2

Copy
4

Explanation for Sample 2

The optimal alpacas to keep are Alpacas 1, 3, 5, and 7.


Comments

There are no comments at the moment.