Dotted Strips
InterviewTime limit3sMemory limit1024 MB
Cut a strip of L squares into as many length-M pieces with exactly N dots each as possible, where only some squares have dots.
- Level
Medium5 of 10
- Topics
- Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Juku has a paper strip made of squares, and some of the squares have dots. Juku wants to cut the strip into pieces so that as many pieces as possible have length exactly squares and exactly dots each. The strip may only be cut at the boundaries between squares.
Input
The first line contains four integers separated by spaces: (), (), (), and (). The squares are numbered starting from one end of the strip.
Each of the next lines contains two integers: the number of a square with dots, and the number of dots on that square. Each such square has between 1 and 1,000 dots. The squares with dots are given in increasing order of their numbers.
Output
Print one integer: the maximum number of pieces with the required properties that Juku can cut from the strip.