Dhaka Regional ACM ICPC 2016 Preleminary Contest Solution G - Repeater

G. Repeater

Score: 1

CPU: 4s
Memory: 1200MB

Hello soldier, welcome to the military base Ground Zero. The enemies are planning to attack our base. Right now, they are camping in the jungle near our camp for the night. We must destroy them before the sunrise.
Now there are N enemy vehicles in a straight line. The distance of the vehicles are d1, d2, d3, d4,,, dn. The distances are all positive integers between 1 to M.
For all practical purpose, you can think of our base and all the vehicles are dots in a straight line.

Now the enemy doesn’t know about our secret weapon the repeater. The repeater is a powerful weapon with which can destroy the enemy vehicles. When firing the repeater, we can choose a parameter R and the repeater will first destroy everything at exactly Rdistance away, then it will destroy everything in 2R distance, then 3R, 4R until all the multiples of R less than or equal M are destroyed. Once fired, the repeater can’t be stopped. Now your job is to operate the repeater.
Now the cost of firing the repeater with parameter R is Floor(M/R). We want to destroy all the enemy vehicles but we also want to minimize the cost. You can fire the repeater as many times as you want.
So now if M is 10 and enemy vehicles are at 2, 6 and 9 distance away, we can fire the repeater with parameter R=1 and destroy them but the cost will be Floor(10/1) = 10. Better approach is firing with parameter R=2 and R=9 where the total cost will be Floor(10/2) + Floor(10/9) = 5 + 1 = 6.
So, soldier, your mission is to destroy all the enemy vehicles with minimum cost. Don’t disappoint us.

Input

First line of the input is T(≤100), then T test cases follows. Each case start with a line containing 2 positive integers N (1 ≤ N ≤ 17) the number of enemy vehicles and M (1 ≤ M ≤ 1000000). Next line will be N positive integers d1, d2, d3 ,,, ddn ( 1 ≤ di ≤ M ) which are distances of enemy vehicles.

Output

For each test case print a line in “Case I: C” format where I is case number and C is the minimum cost for destroying all the enemy vehicles.

Sample

InputOutput
1 3 10 2 6 9














Comments

Popular posts from this blog

Solution - Timus Problem 1293. Eniya

Solution - Codeforces Problem 327B - Hungry Sequence

Solution - Timus Problem 1409. Two Gangsters