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 cookies( int const & _minSweetness , std::vector<int> const & _sweetnesses ){ using namespace std; using Sweetness_t = remove_reference< decltype(_sweetnesses)>::type::value_type; auto comp = greater<Sweetness_t>(); auto sweetnesses = priority_queue< Sweetness_t, vector<Sweetness_t>, decltype(comp)>( begin(_sweetnesses), end(_sweetnesses), comp); Sweetness_t x = 0; Sweetness_t y = 0; auto minSteps = 0; while( sweetnesses.size() >= 2 && sweetnesses.top() < _minSweetness){ ++minSteps; x = sweetnesses.top(); sweetnesses.pop(); y = sweetnesses.top(); sweetnesses.pop(); sweetnesses.emplace(x + 2 * y); } return sweetnesses.top() >= _minSweetness ? minSteps : -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
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 :) )