#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e7+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll m, q;
ll p[(int)1e5 + 5];
ll buyp[(int)1e7 + 5];
int ans[MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
#endif
cin>>m>>q;
memset(ans, 0x7f, sizeof(ans));
for(int i = 0; i < m; i++){
cin>>p[i];
for(int j = 0; j <= 1e7; j += p[i]){
buyp[j] = p[i];
}
}
int last = 0;
ans[0] = 0;
for(int i = 1; i <= 1e7; i++){
while(last + buyp[last] <= i && last <= i) last++;
if(last < i) ans[i] = ans[last] + 1;
else break;
}
for(int i = 0; i < q; i++){
int n;
cin>>n;
if(ans[n] >= 2139062143){
cout<<"oo"<<endl;
}else{
cout<<ans[n]<<endl;
}
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
117752 KB |
Output is correct |
2 |
Correct |
122 ms |
117880 KB |
Output is correct |
3 |
Correct |
86 ms |
117752 KB |
Output is correct |
4 |
Correct |
93 ms |
117880 KB |
Output is correct |
5 |
Correct |
118 ms |
117724 KB |
Output is correct |
6 |
Correct |
70 ms |
117752 KB |
Output is correct |
7 |
Correct |
85 ms |
117904 KB |
Output is correct |
8 |
Correct |
96 ms |
117752 KB |
Output is correct |
9 |
Correct |
144 ms |
117752 KB |
Output is correct |
10 |
Correct |
162 ms |
117752 KB |
Output is correct |
11 |
Correct |
147 ms |
117880 KB |
Output is correct |
12 |
Correct |
90 ms |
117752 KB |
Output is correct |
13 |
Correct |
246 ms |
117880 KB |
Output is correct |
14 |
Correct |
247 ms |
117944 KB |
Output is correct |
15 |
Correct |
125 ms |
117752 KB |
Output is correct |
16 |
Correct |
117 ms |
117808 KB |
Output is correct |
17 |
Correct |
114 ms |
117880 KB |
Output is correct |
18 |
Correct |
95 ms |
117752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
117912 KB |
Output is correct |
2 |
Correct |
120 ms |
119032 KB |
Output is correct |
3 |
Correct |
293 ms |
118720 KB |
Output is correct |
4 |
Correct |
125 ms |
117752 KB |
Output is correct |
5 |
Correct |
206 ms |
118520 KB |
Output is correct |
6 |
Correct |
110 ms |
117752 KB |
Output is correct |
7 |
Correct |
109 ms |
117880 KB |
Output is correct |
8 |
Correct |
122 ms |
117752 KB |
Output is correct |
9 |
Correct |
235 ms |
118944 KB |
Output is correct |
10 |
Correct |
302 ms |
118716 KB |
Output is correct |
11 |
Correct |
290 ms |
118392 KB |
Output is correct |
12 |
Correct |
168 ms |
117752 KB |
Output is correct |
13 |
Correct |
100 ms |
117752 KB |
Output is correct |
14 |
Correct |
125 ms |
117752 KB |
Output is correct |
15 |
Correct |
248 ms |
118396 KB |
Output is correct |
16 |
Correct |
123 ms |
119032 KB |
Output is correct |
17 |
Correct |
248 ms |
117752 KB |
Output is correct |
18 |
Correct |
246 ms |
119160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
118940 KB |
Output is correct |
2 |
Correct |
304 ms |
118776 KB |
Output is correct |
3 |
Correct |
307 ms |
118904 KB |
Output is correct |
4 |
Correct |
199 ms |
118648 KB |
Output is correct |
5 |
Correct |
154 ms |
119416 KB |
Output is correct |
6 |
Correct |
259 ms |
118776 KB |
Output is correct |
7 |
Correct |
216 ms |
119160 KB |
Output is correct |
8 |
Correct |
264 ms |
118776 KB |
Output is correct |
9 |
Correct |
262 ms |
118776 KB |
Output is correct |
10 |
Correct |
199 ms |
118012 KB |
Output is correct |
11 |
Correct |
164 ms |
118072 KB |
Output is correct |
12 |
Correct |
230 ms |
118080 KB |
Output is correct |
13 |
Correct |
295 ms |
118776 KB |
Output is correct |
14 |
Correct |
189 ms |
118952 KB |
Output is correct |
15 |
Correct |
245 ms |
118136 KB |
Output is correct |
16 |
Correct |
268 ms |
118136 KB |
Output is correct |
17 |
Correct |
231 ms |
118460 KB |
Output is correct |
18 |
Correct |
306 ms |
118776 KB |
Output is correct |
19 |
Correct |
107 ms |
118136 KB |
Output is correct |
20 |
Correct |
311 ms |
118848 KB |
Output is correct |
21 |
Correct |
211 ms |
118904 KB |
Output is correct |
22 |
Correct |
345 ms |
119416 KB |
Output is correct |
23 |
Correct |
160 ms |
118776 KB |
Output is correct |
24 |
Correct |
136 ms |
118648 KB |
Output is correct |
25 |
Correct |
211 ms |
118648 KB |
Output is correct |
26 |
Correct |
198 ms |
118648 KB |
Output is correct |
27 |
Correct |
330 ms |
119324 KB |
Output is correct |
28 |
Correct |
128 ms |
118652 KB |
Output is correct |
29 |
Correct |
292 ms |
119416 KB |
Output is correct |
30 |
Correct |
263 ms |
119096 KB |
Output is correct |
31 |
Correct |
151 ms |
118648 KB |
Output is correct |
32 |
Correct |
162 ms |
118664 KB |
Output is correct |
33 |
Correct |
119 ms |
118556 KB |
Output is correct |
34 |
Correct |
217 ms |
119160 KB |
Output is correct |
35 |
Correct |
132 ms |
118648 KB |
Output is correct |
36 |
Correct |
318 ms |
119484 KB |
Output is correct |
37 |
Correct |
153 ms |
119416 KB |
Output is correct |
38 |
Correct |
258 ms |
118780 KB |
Output is correct |
39 |
Correct |
140 ms |
118648 KB |
Output is correct |
40 |
Correct |
223 ms |
118652 KB |
Output is correct |
41 |
Correct |
198 ms |
119172 KB |
Output is correct |
42 |
Correct |
277 ms |
118904 KB |
Output is correct |