This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,q;
long long dp[10009];
int a[10009];
long long d(int x)
{
if (x==0)return 0;
if (dp[x]!=-1)return dp[x];
long long mn=1000000000;
for(int i=0;i<n;i++)
{
if (x%a[i]!=0)mn=min(mn,1+d(x-(x%a[i])));
}
return mn;
}
int main()
{
cin>>n>>q;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
int x;
memset (dp,-1,sizeof dp);
while (q--)
{
cin>>x;
long long u=d(x);
if (u>=1000000)cout<<"oo"<<endl;
else cout<<u<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |