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;
const int nx=1e7+5;
int dp[nx], n, m, x, q, p, res[nx], t, cnt;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>m>>q;
for (int i=0; i<m; i++)
{
cin>>x;
for (int j=x; j<nx; j+=x) dp[j]=x;
}
for (int i=x; i<nx; i++) res[i]=-1;
for (int i=0; i<x; i++) res[i]=1;
t=1;
while (p<nx)
{
int mx=x;
t++;
for (int i=p; i<min(nx-1, x); i++) mx=max(mx, i+dp[i]);
for (int i=x; i<min(nx-1, mx); i++) res[i]=t;
if (mx==x) break;
p=x;
x=mx;
}
//for (int i=0; i<35; i++) cout<<i<<' '<<res[i]<<'\n';
while (q--)
{
cin>>x;
if (res[x]==-1) cout<<"oo\n";
else cout<<res[x]<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |