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.
My solution in Java language. Sorry because this time, i excluded the explaination.
publicstaticinthowManyGames(intp,intd,intm,ints){// Return the number of games you can buyintgames=(p-m)/d+1;intprice=(p+p-(games-1)*d)*games/2;if(s<price){intmid=games/2;intstart,end,i;if(s<(p+p-(mid-1)*d)*mid/2){start=mid-1;end=0;}elseif(s==(p+p-(mid-1)*d)*mid/2){returnmid;}else{start=games-1;end=mid;}for(i=start;i>=end&&s<(p+p-(i-1)*d)*i/2;i--){}games=i;}else{games+=(s-price)/m;}returngames;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Halloween Sale
You are viewing a single comment's thread. Return to all comments →
My solution in Java language. Sorry because this time, i excluded the explaination.