We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For those of you struggling, consider a greedy approach where you always buy resources when possible, and check for that number of resources how many more iterations it would take to exceed n from the current point. This is O(n) but you can build shortcuts into the code by noting that whenever you dont have enough funds to afford resources, you can "skip" to the next point at which you can and increment the rounds accordingly. This approach passes all test cases. Watch out for overflow too and make everything unsigned long long if you're in C++.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Making Candies
You are viewing a single comment's thread. Return to all comments →
For those of you struggling, consider a greedy approach where you always buy resources when possible, and check for that number of resources how many more iterations it would take to exceed n from the current point. This is O(n) but you can build shortcuts into the code by noting that whenever you dont have enough funds to afford resources, you can "skip" to the next point at which you can and increment the rounds accordingly. This approach passes all test cases. Watch out for overflow too and make everything unsigned long long if you're in C++.