Simple O(n) Greedy Solution


#1
vector<int> Solution::solve(int A, vector<int> &arr) {
    int n = arr.size(), 
    min_ind = min_element(arr.begin(), arr.end()) - arr.begin(),
    max_l = A / arr[min_ind];
    vector<int> ans;
    int ps = A, tk = 0;
    for(int i =0 ; i <= min_ind; i ++){
        while((A >= arr[i]) && ((tk + 1 + ((A - arr[i])/ arr[min_ind])) == max_l)){
            tk ++;
            A -= arr[i];
            ans.push_back(i);
        }
    }
    return ans;
}