#C5456. Maximum Villagers Water Fetching
Maximum Villagers Water Fetching
Maximum Villagers Water Fetching
A group of villagers need to fetch water from a common well. Each villager has a preferred start time and a required duration for fetching the water. The finishing time for a villager is defined as \( s_i + d_i \), where \( s_i \) is the start time and \( d_i \) is the duration.
Two villagers conflict if the start time of one is less than the finishing time of the previously scheduled villager. In other words, if we choose a villager whose interval is \([s_i, s_i+d_i)\), then any next chosen villager must satisfy:
[ s_j \geq s_i + d_i ]
Your task is to determine the maximum number of villagers that can fetch water sequentially without any overlapping intervals.
inputFormat
The input is given in stdin as follows:
- The first line contains an integer \( n \), representing the number of villagers.
- The following \( n \) lines each contain two integers \( s_i \) and \( d_i \) (separated by space), where \( s_i \) is the start time and \( d_i \) is the duration for the \( i^{th} \) villager.
outputFormat
Output a single integer to stdout — the maximum number of villagers that can use the well without any overlapping intervals.
## sample5
1 3
2 2
3 1
6 1
7 2
3