101552024-03-28 19:34:28111Az óvodai lét elviselhetetlen könnyűsége #2cpp17Time limit exceeded 20/1001.582s8548 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];
	}
	vector<int>dp(MA);
	dp[0]=1;
	for(int i=1;i<MA;i++){
		int h=0;
		for(int j=0;j<M;j++){
			h=max(h,dp[i-1]*(v[j]-1)%v[j]);
		}
		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
1Accepted3ms2032 KiB
2Accepted52ms2460 KiB
subtask220/20
3Accepted6ms2884 KiB
4Accepted8ms2744 KiB
5Accepted9ms2868 KiB
6Accepted8ms2732 KiB
7Accepted29ms2996 KiB
8Accepted135ms3172 KiB
9Accepted264ms3120 KiB
10Accepted592ms3272 KiB
subtask30/10
11Accepted32ms3504 KiB
12Accepted52ms3616 KiB
13Accepted57ms3592 KiB
14Accepted56ms3640 KiB
15Accepted89ms3648 KiB
16Accepted64ms3868 KiB
17Time limit exceeded1.565s3780 KiB
subtask40/15
18Accepted411ms4180 KiB
19Accepted279ms4340 KiB
20Time limit exceeded1.582s4428 KiB
21Accepted395ms4876 KiB
22Time limit exceeded1.575s4932 KiB
23Accepted57ms4808 KiB
24Accepted57ms4832 KiB
25Accepted59ms4984 KiB
26Accepted90ms4716 KiB
27Time limit exceeded1.555s4200 KiB
subtask50/55
28Time limit exceeded1.542s4696 KiB
29Time limit exceeded1.57s4736 KiB
30Accepted1.09s5560 KiB
31Accepted328ms6204 KiB
32Accepted1.259s6860 KiB
33Accepted416ms7504 KiB
34Accepted65ms7472 KiB
35Accepted79ms7680 KiB
36Accepted1.34s8392 KiB
37Time limit exceeded1.555s8548 KiB
38Time limit exceeded1.542s8028 KiB
39Time limit exceeded1.562s8352 KiB