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;
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e7 + 15;
int n, m, q, k, a[N];
int mx[N], dp[N];
main() {
memset(dp, 0x3f, sizeof(dp));
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> m >> q;
while(m--) {
int p;
cin >> p;
for(int i = p - 1; i < N; i += p)
Max(mx[i], p - 1);
}
for(int i = N - 2; i; --i)
Max(mx[i], mx[i + 1] - 1);
dp[0] = 0;
for(int i = 1; i < N; ++i)
Min(dp[i], dp[i - mx[i]] + 1);
while(q--) {
int x;
cin >> x;
if(dp[x] == inf)
cout << "oo" << endl;
else
cout << dp[x] << endl;
}
return 0;
}
Compilation message (stderr)
brunhilda.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |