Under construction

Still being built. Things may change

Intensive Training

Time limit1sMemory limit2048 MB

Summary
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 NN days (numbered from 11 to NN). 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 1010010^{100} problems that you can pick to solve.

You want to plan a schedule for your intensive training. On day ii, you plan to solve exactly kik_i problems, each with difficulty rating rir_i, where kik_i and rir_i are non-negative integers. On a single day, you may solve 00 problems with a non-zero rating, which means you do not solve any problems that day. You may also solve multiple problems with difficulty 00, 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, ki−1≥kik_{i-1} \ge k_i and ri−1≤rir_{i-1} \le r_i for 2≤i≤N2 \le i \le N.
  • To avoid burning out, the total number of problems must be exactly KK, and the sum of difficulty ratings across all days must be exactly RR. Formally, k1+k2+⋯+kN=Kk_1 + k_2 + \cdots + k_N = K and r1+r2+⋯+rN=Rr_1 + r_2 + \cdots + r_N = R.

The productivity of a day is the number of problems solved that day multiplied by their difficulty rating, that is, ki×rik_i \times r_i. Find the maximum total productivity across all NN days.

Input

This is a multi-case problem. The first line contains an integer TT (1≤T≤1001 \le T \le 100), the number of test cases.

Each test case consists of one line with three integers NN, RR, and KK (1≤N,R,K≤1091 \le N, R, K \le 10^9).

Output

For each test case, print the maximum total productivity on a single line as an integer.

Examples1

  1. Example 1

    Input
    4
    3 4 7
    2 1 1
    1 1000000000 1000000000
    1043 104812 99818
    
    Expected output
    9
    0
    1000000000000000000
    10030642