Shortest C++ Code


#1
vector<int> Solution::solve(int A, vector<int> &B) 
{
    int idx=min_element(B.begin(),B.end())-B.begin();
    int m=B[idx],l=A/m,rem=A-m*l,i=0;   //l is the max possible length(we return vec of this l)
    if(rem==0) return vector<int> (l,idx);  //rem is remaining value if we fill entire vec with m's
    vector<int> res;
    while(res.size()<l)
    {
        if((B[i]-m)<=rem)
        {
            res.push_back(i);
            rem=rem-(B[i]-m);
        }
        else i++;
    }
    return res;
}