This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;
const int MX = 1e7+7;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
vi A(N); for(auto& x : A) cin >> x;
vi q(Q); for(auto& x : q) cin >> x;
int mx = *max_element(begin(q), end(q));
vi C(N, -1);
vi X = {0}; int cur = 1;
while(cur <= mx) {
int ncur = 0;
for(int i = 0; i < N; i++) {
if (C[i] < cur) C[i] = ((cur + A[i] - 1) / A[i]) * A[i];
// cout << i << " " << C[i] << endl;
ncur = max(ncur, C[i]);
}
if (cur == ncur) break;
// cout << ncur << endl;
X.pb(ncur - 1);
cur = ncur;
}
for(auto x : q) {
auto it = lower_bound(begin(X), end(X), x);
if (it == end(X)) cout << "oo" << nl;
else cout << int(it - begin(X)) << nl;
}
exit(0-0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |