101592024-03-28 19:50:14111Az óvodai lét elviselhetetlen könnyűsége #2cpp17Wrong answer 30/10048ms7852 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MA (int)1e5

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.rbegin(),v.rend());
	int A=1e5;
	vector<int>dp(A);
	dp[0]=1;
	for(int i=1;i<A;i++){
		int h=0;
		for(int j=0;j<M&&j<100&&v[j]>h;j++){
			h=max(h,dp[i-1]*(v[j]-1)%v[j]);
		}
		if(h==0||dp[i-1]>1e7){
			A=i;
		}
		dp[i]=dp[i-1]+h;
	}
	while(Q--){
		int N;
		cin>>N;
		int l=0,h=A;
		while(l<h){
			int m=(l+h)/2;
			if(dp[m]>N){
				h=m;
			}
			else{
				l=m+1;
			}
		}
		cout<<(h==A?0:h)<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms3164 KiB
2Accepted25ms3524 KiB
subtask220/20
3Accepted4ms3828 KiB
4Accepted4ms4012 KiB
5Accepted4ms4116 KiB
6Accepted17ms4072 KiB
7Accepted9ms4072 KiB
8Accepted7ms4072 KiB
9Accepted8ms4380 KiB
10Accepted7ms4592 KiB
subtask310/10
11Accepted23ms4860 KiB
12Accepted24ms4772 KiB
13Accepted24ms4968 KiB
14Accepted23ms4988 KiB
15Accepted21ms4992 KiB
16Accepted24ms5248 KiB
17Accepted28ms6580 KiB
subtask40/15
18Wrong answer3ms4932 KiB
19Accepted3ms5236 KiB
20Accepted16ms6844 KiB
21Accepted4ms5284 KiB
22Wrong answer17ms7008 KiB
23Accepted3ms5408 KiB
24Accepted3ms5344 KiB
25Accepted3ms5348 KiB
26Accepted3ms5492 KiB
27Accepted14ms6512 KiB
subtask50/55
28Accepted37ms7116 KiB
29Accepted35ms7196 KiB
30Wrong answer27ms5696 KiB
31Wrong answer28ms5652 KiB
32Accepted26ms5956 KiB
33Wrong answer26ms5864 KiB
34Accepted32ms5848 KiB
35Accepted28ms6060 KiB
36Wrong answer32ms6404 KiB
37Accepted30ms6488 KiB
38Accepted41ms7136 KiB
39Accepted48ms7852 KiB