#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, q;
int tobest[10000005];
int last[10000005];
int ans[10000005];
int ask[100005], p[100005];
int maxsolved=0, maxask=0;
bool used[10000005];
void eras()
{
for(int i=1; i<=n; i++)
{
if(p[i]!=p[i-1])
{
for(int j=0; j<=maxask; j+=p[i])
{
last[j]=max(last[j], j+p[i]-1);
}
}
}
}
void solve()
{
int j=0;
tobest[0]=p[n]-1;
for(int i=0; i<=10000000; i++)
{
if(tobest[i]==0) return;
if(i>0) j=tobest[j-1]+1;
for(int k=j; k<=tobest[i]; k++)
{
if(k>maxask) return;
tobest[i+1]=max(tobest[i+1], last[k]);
ans[k]=i;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1; i<=n; i++)
{
cin>>p[i];
}
sort(p+1, p+n+1);
for(int i=1; i<=q; i++)
{
cin>>ask[i];
maxask=max(maxask, ask[i]);
}
eras();
solve();
// for(int i=0; i<=5; i++)
// {
// cout<<tobest[i]<<endl;
// }
for(int i=1; i<=q; i++)
{
if(ans[ask[i]]==0) cout<<"oo\n";
else cout<<ans[ask[i]]+1<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
424 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
484 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
14 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
632 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
77884 KB |
Output is correct |
2 |
Correct |
208 ms |
71296 KB |
Output is correct |
3 |
Correct |
129 ms |
37472 KB |
Output is correct |
4 |
Incorrect |
580 ms |
71204 KB |
Output isn't correct |
5 |
Correct |
52 ms |
20856 KB |
Output is correct |
6 |
Correct |
122 ms |
27512 KB |
Output is correct |
7 |
Correct |
176 ms |
77816 KB |
Output is correct |
8 |
Correct |
298 ms |
29688 KB |
Output is correct |
9 |
Correct |
51 ms |
21024 KB |
Output is correct |
10 |
Correct |
136 ms |
37548 KB |
Output is correct |
11 |
Correct |
457 ms |
78752 KB |
Output is correct |
12 |
Incorrect |
984 ms |
67324 KB |
Output isn't correct |
13 |
Incorrect |
218 ms |
78152 KB |
Output isn't correct |
14 |
Incorrect |
590 ms |
71316 KB |
Output isn't correct |
15 |
Correct |
72 ms |
25464 KB |
Output is correct |
16 |
Correct |
141 ms |
71216 KB |
Output is correct |
17 |
Execution timed out |
1067 ms |
66880 KB |
Time limit exceeded |
18 |
Correct |
272 ms |
79112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
315 ms |
79140 KB |
Output isn't correct |
2 |
Incorrect |
385 ms |
78940 KB |
Output isn't correct |
3 |
Correct |
304 ms |
56212 KB |
Output is correct |
4 |
Incorrect |
751 ms |
79392 KB |
Output isn't correct |
5 |
Correct |
164 ms |
79624 KB |
Output is correct |
6 |
Incorrect |
686 ms |
79324 KB |
Output isn't correct |
7 |
Correct |
221 ms |
56264 KB |
Output is correct |
8 |
Incorrect |
353 ms |
79036 KB |
Output isn't correct |
9 |
Incorrect |
329 ms |
79156 KB |
Output isn't correct |
10 |
Incorrect |
831 ms |
78968 KB |
Output isn't correct |
11 |
Incorrect |
729 ms |
78840 KB |
Output isn't correct |
12 |
Incorrect |
776 ms |
78948 KB |
Output isn't correct |
13 |
Correct |
156 ms |
40952 KB |
Output is correct |
14 |
Execution timed out |
1062 ms |
26684 KB |
Time limit exceeded |
15 |
Incorrect |
955 ms |
79068 KB |
Output isn't correct |
16 |
Incorrect |
937 ms |
78844 KB |
Output isn't correct |
17 |
Incorrect |
307 ms |
78968 KB |
Output isn't correct |
18 |
Incorrect |
407 ms |
79224 KB |
Output isn't correct |
19 |
Incorrect |
192 ms |
78840 KB |
Output isn't correct |
20 |
Correct |
247 ms |
56300 KB |
Output is correct |
21 |
Execution timed out |
1067 ms |
44924 KB |
Time limit exceeded |
22 |
Incorrect |
341 ms |
79708 KB |
Output isn't correct |
23 |
Incorrect |
215 ms |
79580 KB |
Output isn't correct |
24 |
Incorrect |
694 ms |
79364 KB |
Output isn't correct |
25 |
Execution timed out |
1068 ms |
74548 KB |
Time limit exceeded |
26 |
Incorrect |
749 ms |
79416 KB |
Output isn't correct |
27 |
Correct |
223 ms |
56312 KB |
Output is correct |
28 |
Incorrect |
648 ms |
79548 KB |
Output isn't correct |
29 |
Incorrect |
330 ms |
79736 KB |
Output isn't correct |
30 |
Incorrect |
330 ms |
79632 KB |
Output isn't correct |
31 |
Incorrect |
372 ms |
79196 KB |
Output isn't correct |
32 |
Incorrect |
809 ms |
79424 KB |
Output isn't correct |
33 |
Incorrect |
389 ms |
79224 KB |
Output isn't correct |
34 |
Correct |
168 ms |
56264 KB |
Output is correct |
35 |
Incorrect |
586 ms |
79360 KB |
Output isn't correct |
36 |
Incorrect |
351 ms |
79764 KB |
Output isn't correct |
37 |
Correct |
166 ms |
79612 KB |
Output is correct |
38 |
Incorrect |
677 ms |
79384 KB |
Output isn't correct |
39 |
Incorrect |
609 ms |
79324 KB |
Output isn't correct |
40 |
Incorrect |
514 ms |
79352 KB |
Output isn't correct |
41 |
Incorrect |
143 ms |
56340 KB |
Output isn't correct |
42 |
Execution timed out |
1062 ms |
68180 KB |
Time limit exceeded |