You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
int getMinimumCost( int const & _friends , std::vector<int> & _prices ){ using namespace std; using price_t = remove_reference<decltype(_prices)>::type::value_type; if(static_cast<size_t>(_friends) >= _prices.size()){ return accumulate(begin(_prices), end(_prices), 0); } sort(begin(_prices), end(_prices), greater<price_t>()); auto multiplier = 0; for(auto i = 1; i != _prices.size(); ++i){ if(i % _friends == 0){ ++multiplier; } _prices.at(i) += _prices.at(i - 1) + _prices.at(i) * multiplier; } return _prices.back(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )