#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
const int N = 1e5 + 5;
const int M = 1e7 + 5;
int a[N], ayyr[M], dp[M];
int main () {
// freopen ("input.txt", "r", stdin);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, q;
cin >> n >> q;
int bar = 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (bar > M) continue;
bar *= a[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = a[i] - 1; j < M; j += a[i]) {
ayyr[j] = max (ayyr[j], a[i] - 1);
}
ayyr[M - 1] = max (ayyr[M - 1], (M - 1) % a[i]);
}
for (int i = M - 2; i >= 0; i--) {
ayyr[i] = max (ayyr[i], ayyr[i + 1] - 1);
}
for (int i = 1; i < M; ++i) {
dp[i] = dp[i - ayyr[i]] + 1;
}
while ( q-- ) {
int x;
cin >> x;
if (bar > x) cout << dp[x] << "\n";
else cout << "oo\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... |