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 ll long long
#define el '\n'
#define ld long double
const int maxn=1e7+1,nn=1e5+1;
int f[maxn],oo,a[nn],n,m,q,p;
int take(int z){
if(f[z]>=0) return f[z];
int maxx=z%a[0];
for(int i=1;i<m;++i) maxx=max(maxx,z%a[i]);
f[z]=min(oo,take(z-maxx)+1);
return f[z];
}
int main(){
//freopen("T.INP","r",stdin);
//freopen("T.OUT","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
memset(f,-1,sizeof f);
oo=1e9;
f[0]=0;
cin >> m >> q;
for(int i=0;i<m;++i) cin >> a[i];
while(q--){
cin >> n;
p=take(n);
if(p>=oo) cout << 'o' << 'o' << el;
else cout << p << el;
}
return 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... |