Simple Greedy Soln


#1

vector Solution::solve(int A, vector &B) {
vector ans;
int mn=*min_element(B.begin(),B.end());
int x=min_element(B.begin(),B.end())-B.begin();
while(A>=mn){
ans.push_back(x);
A-=mn;
}
int j=0;
int a=0;
while(a<ans.size() && j<x){
if(A-B[j]+mn>=0){
A=A-B[j]+mn;
ans[a]=j;
a++;}
else j++;
}
return ans;
}