Runtime Error Please Help

vector<int> Solution::solve(int A, vector<int> &B) {
int mn=min_element(B.begin(),B.end())-B.begin();
int minVal = B[mn];
int remain = A%minVal;
int val = A/minVal;

vector<int> ans;
if(val == 0) return ans;

for(int i=0; i<val; i++) ans.push_back(mn);

int idx=0;
for(int i=0; i<mn; i++){
    while(remain >= (B[i]-B[mn])){
        ans[idx++] = i;
        remain = remain - (B[i]-B[mn]);
return ans;

I’m getting runtime error on submit but the same test case is giving correct output in Custom. Please help me identify what might be causing the runtime error ?


I did exactly same mistake. Mine code was very very similar and same error but I tried to debug and found mistake after 1 hour. If you want me to tell the mistake to you just reply else try to debug yourself I know exaclty where is mistake in your code. Hope you’ll find it yourself :grinning: