i was writing the code for no of numbers less than a number C of length b that could be made using elements from a set "a" (same no can be chosen more than once) then while debugging i encountered this wierd problem every time i try to cout<< something in the function it shows a runtime error otherwise executes fine ca someone help me with this thanks for your help
here is the code
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> &a, int b, int C) {
int n=a.size();
int copy=C;
if(C==0||n==0)return 0;
vector <int> c;
while(C>0){
c.push_back((C%10));
C=C/10;
}
//cout<<C; //shows a runtime error if this included otherwise not
int l=c.size();
reverse(c.begin(),c.end());
int flag=0;
if(find(a.begin(),a.end(),0)!=a.end())
flag=1;
if(l>b){
if(flag==1 && b!=1)
return pow(n,b-1)*(n-1);
else
return pow(n,b);
}
if(l<b)
return 0;
if(l==1){
int cth=0;
for(int i=0;i<n;i++){
if(a[i]<c[0])
cth++;
}
return cth;
}
int dp[n][2];
int ctl=0,cte=0;
for(int i=0;i<n;i++){
if(a[i]<c[0]&&a[i]!=0)
ctl++;
if(a[i]==c[0])
cte++;
}
dp[0][0]=ctl;
dp[0][1]=cte;
for(int i=1;i<b;i++){
int ctL=0,ctE=0;
for(int j=0;j<n;j++){if(a[j]<c[i])ctL++; else{if(a[j]==c[i])ctE++;}}
dp[i][0]=dp[i-1][0]*n+dp[i-1][1]*ctL;
dp[i][1]=dp[i-1][1]*ctE;
}
return dp[b-1][0];
}
int main() {
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
cin>>a[i];
int b,c;
cin>>b>>c;
cout<<solve(a,b,c);
}