#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <chrono>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, a;
cin>>n>>q;
vector<int> to(20000001), dp(10000001, 0);
for (int i=1; i<20000001; ++i)to[i]=10000001;
while (n--){
cin>>a;
for (int i=0; i<10000001; i+=a)to[i+a-1]=min(to[i+a-1], i);
}
for (int i=19999999; i>=0; --i)to[i]=min(to[i], to[i+1]);
for (int i=1; i<10000001; ++i){
if (to[i]>=i)dp[i]=10000001;
else dp[i]=dp[to[i]]+1;
}
while (q--){
cin>>a;
if (dp[a]>10000000)cout<<"oo\n";
else cout<<dp[a]<<"\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... |