[Solution] Distinct Numbers CodeChef Solution
Problem
Given an array consisting of distinct integers , we have to perform moves. We perform the following steps in one move:
- Select an integer such that and for all is not equal to any element of the current array.
- Append to .
- The score of this move .
Note that the score is calculated after appending . Thus, can be the maximum element of the array as well.
For e.g. if and we append to , then, becomes and the score of this move is .
Find the maximum sum of scores we can achieve after performing exactly moves.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains three space-separated integers and — the size of the array and the number of moves respectively.
- The second line of each test case contains space-separated integers denoting the array .
Output Format
For each test case, output the maximum sum of scores we can achieve after performing exactly moves.
It is guaranteed that it is always possible to perform moves under the given constraints.
Explanation:
Test Case 1: We can perform the following move:
- Append . Score of this move
Hence, the maximum total score is .
Test Case 2: We can perform the following moves:
- Append . Score of this move
- Append . Score of this move
Hence, the maximum total score is .
Test Case 3: We can perform the following moves:
- Append . Score of this move
- Append . Score of this move
Hence the maximum total score is .
No comments:
Post a Comment