Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

maximise the rides with the given tokens java

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 @SafeVarargs annotation 
Java :: print different variable datatype 
Java :: batch file to switch between java version 
Java :: MinimumAndMaximum 
Java :: Determining what type of data the ArrayList will contain in java. 
Java :: quadratic program 
Java :: convert xml file to node tree with java 
Java :: Access Members of a Class Java 
Java :: java swing place objects vertically 
Java :: java focus to desktop 
Java :: hash tree in java 
Java :: bukkit scheduler self cancelling task 
Java :: convert kotlin to java online 
Java :: what is method overriding in java 
Java :: java length of array 
Java :: java anonymous function 
Java :: annotation spring notnull 
Java :: Java find duplicate items 
Java :: java compare char 
Java :: java string extract words 
Java :: java get class by string name 
Java :: int in string umwandeln 
Java :: como limpar a tela do consola no java 
Sql :: delete all data in neo4j 
Sql :: postgresql reset sequence 
Sql :: how to get yesterday date in sql 
Sql :: oracle create synonym 
Sql :: mysql CURRENT_TIMESTAMP() 
Sql :: find largest table in mysql database 
Sql :: mysql print variable 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =