Intensive Training
Time limit1sMemory limit2048 MB
Given N days, find the maximum sum of k_i times r_i, where k is nonincreasing, r is nondecreasing, sum of k is K, and sum of r is R.
- Level
Hard8 of 10
- Topics
- Math, Greedy, Binary search
- Solved
- No attempts yet
Problem
To prepare for the upcoming ICPC Regional Contest, you decided to train intensively for the next days (numbered from to ). During the intensive training, you want to solve problems from the training platform INCOJ. In INCOJ, each problem has a difficulty rating, which is a non-negative integer. For each rating, there are problems that you can pick to solve.
You want to plan a schedule for your intensive training. On day , you plan to solve exactly problems, each with difficulty rating , where and are non-negative integers. On a single day, you may solve problems with a non-zero rating, which means you do not solve any problems that day. You may also solve multiple problems with difficulty , since those problems are too easy for you.
Your schedule must follow these constraints.
- To focus on quality over quantity, the number of problems on each day cannot exceed the previous day's count, and the difficulty rating cannot be less than the previous day's rating. Formally, and for .
- To avoid burning out, the total number of problems must be exactly , and the sum of difficulty ratings across all days must be exactly . Formally, and .
The productivity of a day is the number of problems solved that day multiplied by their difficulty rating, that is, . Find the maximum total productivity across all days.
Input
This is a multi-case problem. The first line contains an integer (), the number of test cases.
Each test case consists of one line with three integers , , and ().
Output
For each test case, print the maximum total productivity on a single line as an integer.