/*
ID: agageld1
LANG: C++17
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 400005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, t = 1, m, q;
string s, g, h;
vector <int> a;
int main () {
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);
cin >> m >> q;
for(int i= 1;i<=m;i++) {
ll x;
cin >> x;
a.pb(x);
}
sort(a.rbegin(),a.rend());
for(int j = 1;j<=q;j++) {
int x, cnt = 0, tr = 0;
cin >> x;
while(x != 0) {
if(a[0] > x) {
cnt++;
break;
}
int mx = INT_MAX;
for(auto i : a) {
if(mx > (x / i) * i) mx = (x / i) * i;
if(i - 1 <= x - mx) break;
}
if(mx == x) {
tr = 1;
cout << "oo\n";
break;
}
x = mx;
cnt++;
}
if(!tr)cout << cnt << '\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... |