Tanya and Lassi
Practice
3.9 (183 votes)
Dynamic programming
Approved
Easy Medium
Problem
85% Success 3369 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Your friend Tanya has recently launched a new company producing a very tasty version of India traditional drink called Lassi.

It has become very popular, so there are a lot of customers who want to buy it. Recently, she prepared L liters of Lassi ready to sell. Moreover, his marketer sent her a list of L integers corresponding to prices for which bottles of sizes 1, 2, 3, ..., L can be sold.

Since Tanya is good at producing drinks, but not as good as you with algorithms, she asked you to help her to get the maximum possible profit. In more details, you have to decide what is the maximum profit she can get by producing bottles from available L liters of Lassi and selling them to customers for prices given by the marketer. Notice that Tanya can produce any number of bottles of any integer size in a range [1, L], however, she gets money only for bottles full of Lassi.

In one test file, your task is to handle T instances of the above problem.

Constraints:

\(1 \le T \le 10 \)
\(1 \le L \le 10000 \)
price for any bottle is a positive integer not greater than 106

Input format:

In the first line there is one integer T denoting the number of cases to solve. Each of these test cases is given by 2 consecutive lines. In the first of them, there is a single integer L denoting the number of available liters of Lassi. In the second one, there are L integers denoting the prices for which bottles of size 1, 2, 3, ..., L can be sold.

Output format:

In one line, output the maximum profit which Tanya can get by selling L liters of Lassi for given prices.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
176 votes
Tags:
Dynamic ProgrammingApprovedEasy-Medium
Points:30
3 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingImplementationMediumOpenProbabilityStatisticsTwo dimensional
Points:20
21 votes
Tags:
ApprovedCombinatoricsDynamic ProgrammingEasyMathOpen