Multiple sequence
Time limit0.5sMemory limit1024 MB
Choose N integers from M kinds, each kind limited to c_i copies, so every term is a multiple of the previous one, and find the maximum possible sum.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
There are kinds of positive integers. The -th integer has copies. Choose of these integers and build a sequence of length that satisfies the condition below. Find the maximum possible sum of .
- is a multiple of .
Input
The first line contains the length of sequence and the number of kinds , separated by a space. From the second line onward, each of the next lines gives one integer's information. The -th line contains a positive integer and , separated by a space. All are distinct.
Output
Print the maximum sum of sequence . If no such sequence exists, print -1.