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;
int a[100009];
int main()
{
cin>>n>>q;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
int x;
while (q--)
{
cin>>x;
int re=0;
bool r=0;
for(int i=n-1;i>-1;i--)
{
if (x<a[n-1])
{
r=1;
cout<<re+1;
break;
}
if (x==0)
{
r=1;
cout<<re<<endl;break;
}
if (x%a[i]!=0){x=x-(x%a[i]);
re++;}
}
if (r==0&&x<a[n-1])
cout<<re+1<<endl;
else if (r==0)cout<<"00"<<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... |