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;
typedef long long ll;
const int V = 1e7;
int nxt[V + 7], dp[V + 7];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
for (int j = x; j - 1 <= V; j += x) {
nxt[j - 1] = x - 1;
}
nxt[V] = max(nxt[V], V % x);
}
for (int i = V; i >= 1; --i) {
nxt[i] = max(nxt[i], nxt[i + 1] - 1);
}
for (int i = 1; i <= V; ++i) {
if (nxt[i] == 0 || dp[i - nxt[i]] == -1) {
dp[i] = -1;
} else {
dp[i] = dp[i - nxt[i]] + 1;
}
}
while (q--) {
ll x;
cin >> x;
if (dp[x] < 0) {
cout << "oo\n";
} else {
cout << dp[x] << "\n";
}
}
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... |