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;
#define int long long int
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
int nxt(){ int x;cin>>x; return x; }
const int mod = 1e9 +7, sze = 1e7 +10, inf = INT_MAX, LG = 20;
int dp[sze],ff[sze];
void fast(){
int n,q;
cin>>n>>q;
int mx = 0;
for(int i =1;i<=n;i++){
int p;
cin>>p;
mx=max(mx,p);
for(int u = p;u<sze;u+=p){
ff[u-1]= (p-1);
}
ff[sze-1]=max(ff[sze-1],(sze-1)%p);
}
for(int i = sze-1;i>=1;i--){
ff[i]=max(ff[i],ff[i+1]-1);
}
for(int i=1;i<sze;i++){
if(i<mx){
dp[i]=1;
continue;
}
dp[i]=inf;
dp[i]=min(dp[i],dp[i - ff[i]] +1);
}
while(q--){
int v;
cin>>v;
if(dp[v]>=inf){
cout<<"oo"<<endl;
}
else{
cout<<dp[v]<<endl;
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |