#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e7+7, maxn2 = 1e5 + 5;
int n, m, q, reszta;
int dp[maxn], pier[maxn2];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
for(int i = 1; i <= 1e7; i++)
{
dp[i] = 1e9;
}
cin >> m >> q;
for(int i = 1; i <= m; i++)
{
cin >> pier[i];
}
dp[0] = 0;
for(int i = 1; i <= 1e4; i++)
{
// cout << " i " << i << endl;
for(int j = m; j >= 1; j--)
{
if(i >= pier[j])
{
reszta = (i % pier[j]);
// cout << " reszta " << reszta << endl;
dp[i] = min(dp[i], 1 + dp[i-reszta]);
}
else
{
dp[i] = 1; break;
}
}
}
for(int i = 0; i < q; i++)
{
cin >> n;
if(n > 1e4){while(true){reszta++;}}
if(dp[n] >= 1e9)
{
cout << "oo" << '\n';
}
else
{
cout << dp[n] << '\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... |