# Educational Codeforces Round 26 D Round Subset

767人阅读 评论(0)

D. Round Subset
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call the roundness of the number the number of zeros to which it ends.

You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.

Input

The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).

The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).

Output

Print maximal roundness of product of the chosen subset of length k.

Examples
input
3 2
50 4 20

output
3

input
5 3
15 16 3 25 9

output
3

input
3 3
9 77 13

output
0

Note

In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2[4, 20] — product 80roundness 1,[50, 20] — product 1000roundness 3.

In the second example subset [15, 16, 25] has product 6000roundness 3.

In the third example all subsets has product with roundness 0.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long

using namespace std;
const int maxn=205;
ll dp[maxn][60*maxn];
ll map[maxn],ans2;

ll judge(ll x)
{
ll ans1=0;
ll temp=x;
ans2=0;
while(temp)
{
if(x%2==0)
{
ans1++;
x/=2;
}
else
break;
}
while(temp)
{
if(x%5==0)
{
ans2++;
x/=5;
}
else
break;
}

return ans1;
}

int main()
{
ll n,k,i,j,x,ans1,l;
while(cin>>n>>k)
{
memset(dp,-0x3f3f3f3f,sizeof(dp));
dp[0][0]=0;

for(i=0;i<n;i++)
{
cin>>x;
ans1=judge(x);
for(j=k;j>=1;j--)
{
for(l=ans1;l<60*maxn;l++)
{
dp[j][l]=max(dp[j][l],dp[j-1][l-ans1]+ans2);
}
}
}
ll ans=0;
for(i=1;i<60*maxn;i++)
{
ans=max(ans,min(i,dp[k][i]));
}
cout<<ans<<endl;
}
return 0;
}

个人资料
等级：
访问量： 6万+
积分： 2169
排名： 2万+
联系方式
欢迎谈论交流：1245985209
博客专栏
 ACM的进阶之路 文章：87篇 阅读：37699 CodeForce题解 文章：40篇 阅读：17444