Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find maximum number of rides in amusement park python

from heapq import *

def process(arr,n):
    count = 0
    
    heap = []
    
    for i in range(len(arr)):
        heappush(heap,(arr[i],-(len(arr)-i))) # Constructing min-heap with second index as negative of maximum number of rides 
    
    while(n>0 and heap):
        cost,no_of_rides = heappop(heap)
        no_of_rides = -1 * no_of_rides # Changing maximum no_of_rides from negative to positive
        
        div = n//cost

        # If the amount of money is not sufficient to calculate the last number of rides user could take
        if(div<no_of_rides):
            count += div
            break

        # Else decrement the number of tokens by minimum cost * maximum no_of_rides
        else:
            count += no_of_rides
            n -= no_of_rides*cost
    

    return count;
Comment

PREVIOUS NEXT
Code Example
Java :: Java HashMap Class Declaration 
Java :: @exceptionhandler spring boot annotation not found 
Java :: java plugin spigot messsage console 
Java :: Kotlin const to Java 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: java enum valueof() 
Java :: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type project and qualifiers [@Default] 
Java :: javax.servlet.ServletException: javax.servlet.jsp.JspException: Missing message for key 
Java :: set length java 
Java :: how to find a specific character in a string using array 
Java :: java datasource 
Java :: write arraylist to outputstream java byte file 
Java :: how to display same statement multiple times in java 
Java :: java take inpt into arraylist 
Java :: jdbc insert example from input values 
Java :: how to do two constructors with super 
Java :: Simple java questionnaire using json 
Java :: How to convert Javascript return value to String in Android 
Java :: calculate values of array 
Java :: Filter out any non-printable characters 
Java :: java jbutton hover 
Java :: how to generate randome number in desired range java 
Java :: Java Using Looping Construct to Copy Arrays 
Java :: gif to blob java 
Java :: android paint drawtext multiline 
Java :: jaspersoft masking 
Java :: java ultimo dia del mes 
Java :: jagermeister price in bangalore 
Java :: how to use set ForceDarkAllowed(false); in android studio 
Java :: java add forward / at the end of not present 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =