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 N = (int) 1e7 + 22, inf = (int) 1e9;
int dp[N], mx[N];
void solve() {
fill(dp, dp + N, inf);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = a[i]; j < N; j += a[i]) {
mx[j - 1] = max(mx[j - 1], a[i] - 1);
}
mx[N - 1] = max(mx[N - 1], (N - 1) % a[i]);
}
for (int i = N - 1; i > 0; i--) {
mx[i] = max(mx[i], mx[i + 1] - 1);
}
dp[0] = 0;
for (int i = 1; i < N; i++) {
if (!mx[i]) {
continue;
}
dp[i] = min(inf, dp[i - mx[i]] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) {
cout << "oo\n";
} else {
cout << dp[x] << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |