#P14093. [ICPC 2023 Seoul R] Product Delivery
[ICPC 2023 Seoul R] Product Delivery
题目描述
There is only one railway line connecting cities developed along the coastline. When cities along the coast are sequentially identified by numbers between and , city and city () are connected by rail, but other cities are not connected by rail.
Since every city except city is famous as a tourist destination, every city () excluding city is preparing a variety of goods to welcome travelers ahead of the tourist season. Worldwide famous goods BFB is the most popular item in every city. However, the supplier of this product is located in city .
There is only one store that sells BFB in each city (). Let be the BFB specialty store in city . In each , the number of BFBs expected to be sold in the tourist season is analyzed and reported to the supplier in the form of . Here, and represent the minimum and the maximum number of expected required products, respectively.
The BFB supply company in city collects request information from stores in every city and supplies products according to the rules described below.
- Select a city, say city (). Then, take a train departing from city , travel to city , and supply BFBs only to the stores along the route. In other words, the BFB supplier supplies products to .
- Let be the number of BFBs supplied to () while moving along the route, the condition () must be satisfied.
If the supplier supplies products according to the supply rules described above, it may be impossible for every store to supply the desired number of items with a single supply procedure. Therefore, the supplier must go through several supply procedures to deliver the products but must comply with the supply rules described above each time. After completing all supply procedures, each will have at least and at most items.
For example, suppose and the number of items required by each store () are , and , respectively. In order for each store to supply the desired quantity of goods, there must be at least two delivery procedures. In the first delivery procedure, items can be supplied to each of the stores. Once delivery is completed in this first procedure, all stores' requests except are satisfied. Since items have already been delivered to , () additional products will be delivered to in the second delivery procedure. Of course, there may be other delivery methods. However, at least two delivery procedures are required.
Write a program to calculate the minimum number of supply procedures in order to supply the number of BFBs required by each store according to the above rules.
输入格式
Your program is to read from standard input. The input starts with a line containing an integer (), where is the number of cities in which the BFB specialty stores locate. In the following lines, the -th line contains two integers and () which indicate the minimum and the maximum number of expected required products by .
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of supply processes in order to supply the number of products required by each store according to the delivery rules.
4
13 15
5 8
6 14
3 7
2
5
1 2
2 3
33 44
4 5
6 7
2
5
10 20
3 6
13 30
7 8
11 13
3