101562024-03-28 19:43:12111Az óvodai lét elviselhetetlen könnyűsége #2cpp17Wrong answer 30/10089ms9888 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MA (int)1e4

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int M,Q;
	cin>>M>>Q;
	vector<int>v(M);
	for(int i=0;i<M;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	vector<int>dp(MA);
	dp[0]=1;
	for(int i=1;i<MA;i++){
		int h=0;
		for(int j=max(0ll,M-100);j<M;j++){
			h=max(h,dp[i-1]*(v[j]-1)%v[j]);
		}
		if(h==0){
			fill(dp.begin()+i,dp.end(),dp[i-1]);
		}
		dp[i]=dp[i-1]+h;
	}
	while(Q--){
		int N;
		cin>>N;
		int l=0,h=MA;
		while(l<h){
			int m=(l+h)/2;
			if(dp[m]>N){
				h=m;
			}
			else{
				l=m+1;
			}
		}
		cout<<(h==MA?0:h)<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted50ms2032 KiB
2Accepted79ms2448 KiB
subtask220/20
3Accepted52ms2680 KiB
4Accepted56ms2244 KiB
5Accepted57ms2244 KiB
6Accepted8ms2496 KiB
7Accepted17ms2712 KiB
8Accepted17ms2988 KiB
9Accepted17ms3028 KiB
10Accepted17ms3316 KiB
subtask310/10
11Accepted79ms3084 KiB
12Accepted86ms3304 KiB
13Accepted86ms3288 KiB
14Accepted65ms3360 KiB
15Accepted35ms3476 KiB
16Accepted78ms3468 KiB
17Accepted41ms5284 KiB
subtask40/15
18Wrong answer16ms3984 KiB
19Accepted16ms4128 KiB
20Accepted28ms5336 KiB
21Accepted16ms4412 KiB
22Wrong answer29ms5932 KiB
23Accepted64ms4228 KiB
24Accepted64ms4224 KiB
25Accepted64ms4228 KiB
26Accepted30ms4236 KiB
27Accepted26ms4852 KiB
subtask50/55
28Accepted52ms6228 KiB
29Accepted52ms6880 KiB
30Wrong answer41ms5816 KiB
31Wrong answer41ms5732 KiB
32Accepted39ms6036 KiB
33Wrong answer39ms6072 KiB
34Accepted79ms6172 KiB
35Accepted89ms6120 KiB
36Wrong answer46ms6312 KiB
37Accepted45ms6852 KiB
38Accepted54ms8460 KiB
39Accepted61ms9888 KiB