Not able to figure out the code for the given problem and the logic

#include
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int query;
cin>>query;
int b[query];
int k[query];
for(int i=0;i<query;i++){
cin>>b[i]>>k[i];
}
for(int i=0;i<query;i++){
int flag=0;
int sum=0;
for(int j=0;j<n && sum<=b[i];j++){
if(b[i]==a[j]){
sum+=a[j];
}
if(i!=j){
flag++;
}
}

	if(k[i]==flag){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

}
return 0;

}

logic:
step1 : take value of n and take value of prices of each item in an array a[]
step 2: and then take the no of queries ‘q’
step 3: then make a loop for each query, and for each query take value of A and k ( A is units of money , k is no of atleast items from which she can choose from so that she can spend her whole money)
step 4: for each query check :

for(int j=0;j<n;j++){
            if((A%a[j])==0){   // if a[i] divides A completely then only she will be able to spend her whole money and she can buy this item.......
                k1++;
           }
        }

step 5 : check k1 and k

            if(k1>=k)  // k is atleast no of item that she can buy
			cout<<"Yes"<<endl;
	       	else
			cout<<"No"<<endl;

Reference Code:

i hope this help if you have further doubt, feel free to ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.