What is the problem with this code giving :Runtime Error. runtime error. ex: division by zero, array index out of bounds, uncaught exception


#1
vector<int> Solution::solve(int A, vector<int> &B) {
    vector<vector<int>>dp(B.size());
    for(int i=0;i<B.size();i++){
        int t =A;
        vector<int> temp;
        temp.clear();
        while(t>=B[i]){//this has mistake
            temp.push_back(i);
            t-=B[i];
        }
        if( t!=0 && i<(B.size()-1))
        {
            for(int j=i+1;j<B.size();j++)
            {
                if(B[j]==t)
                temp.push_back(j);
            }
            
        }
        dp[i]=temp;
    }
        int high=-1;
        for(int i=0;i<B.size();i++){
            if(dp[i].size()>high)
                high=i;
        }
        return dp[high];
    
}