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 mx = (int) 1e7 + 37;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q; cin >> n >> q;
vector<int> a(n), d(mx), dp(mx, 1e9);
for (int &x : a) {
cin >> x;
for (int i = x - 1; i < mx; i += x) {
d[i] = max(d[i], x - 1);
}
}
for (int i = mx - 2; i; i--) d[i] = max(d[i], d[i + 1] - 1);
dp[0] = 0;
for (int i = 1; i < mx; i++) {
dp[i] = dp[i - d[i]] + 1;
}
while (q--) {
int x; cin >> x;
cout << (dp[x] >= 1e9 ? "oo" : to_string(dp[x])) << '\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... |