#GL0000329. Nhãn giá các gói kẹo (Candy Store)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhãn giá các gói kẹo (Candy Store)
Candy Store
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A store sells candy types in the fixed order . For type , there are candies, each costing coins.
All candies must be packed, each pack containing candies of only one type. For type , choose a positive integer candies per pack with . One pack of this type costs .
A single price tag can cover a contiguous segment of types only when . Choose the pack sizes to minimize the total number of tags. Nonadjacent segments may have the same price but still require different tags.
PHOJ input adaptation: Each test file contains one instance with candy types; the original contest's leading number of test cases is omitted.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum number of price tags.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; , .
- Subtask 3 (50 points): ; , .
Examples
Example 1
Input
4
20 3
6 2
14 5
20 7
Output
2
Explanation
Choose ; pack prices become . One tag covers types –, another covers –. A single price for all four types is impossible.
Example 2
Input
3
444 5
2002 10
2020 2
Output
1
Explanation
Choose , so all pack prices equal : . Every divides .
Example 3
Input
5
7 7
6 5
15 2
10 3
7 7
Output
3
Explanation
Use segments , , . The middle pack price can be , using ; the ends cost . The end segments are not contiguous and thus require separate tags.