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
#define pii pair<long long, long long>
#define fr first
#define se second
int inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e7 + 10;
int dp[MAXN + 10], trans[MAXN + 10];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
for (int j = (a - 1); j <= MAXN; j += a) {
trans[j] = a - 1;
}
trans[MAXN] = max(trans[MAXN], MAXN % a);
}
for (int i = MAXN; i >= 1; i--) {
trans[i] = max(trans[i], trans[i + 1] - 1);
}
for (int i = 1; i <= MAXN; i++) {
dp[i] = inf;
dp[i] = min(dp[i], dp[i - trans[i]] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) cout << "oo\n";
else cout << 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... |