Maximize the Minimum

 JJ has an array 

of size . He can perform the following operations on the array at most

times:

  • Set
where
  • Set
  • where

    He wants to maximize the value of the minimum element of the array

    . Formally, he wants to maximize the value of

    .

    Can you help him do so?

    Input Format

    • The first line contains a single integer
  • - the number of test cases. Then the test cases follow.
  • The first line of each test case contains two integers
  • and - the size of the array
  • and the maximum number of operations allowed respectively.
  • The second line of each test case contains
  • space-separated integers denoting the array
    • .

    Output Format

    For each test case, output the maximum value of the minimum element of the array

    that can be obtained after applying the given operation at most

    times.

    Constraints

  • Sum of
  • over all test cases does not exceed

    Sample Input 1

    4
    5 4
    5 4 3 2 1
    6 1
    8 2 3 9 6 10
    5 2
    4 3 4 3 5
    5 1000
    4 3 4 3 5
    

    Sample Output 1

    5
    3
    4
    5
    

    Explanation

    Test Case 1: We can perform the following operations (in the following order):

    • Set
    . Array becomes
  • Set
  • . Array becomes
  • Set
  • . Array becomes
  • Set
  • . Array becomes

    Therefore the answer is

    .

    Test Case 2: We can perform the following operations (in the following order):

    • Set
    . Array becomes

    Therefore the answer is

    .

    Test Case 3: We can perform the following operations (in the following order):

    • Set
    . Array becomes
  • Set
  • . Array becomes

    Therefore the answer is

    .

    Comments

    Popular posts from this blog

    Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

    Flipkart Runway: Season 3 | 2025 | Internship

    Python for Data Science NPTEL Assignment Solutions Week 4 2022

    GATE 2022 Answer Key Release Date Announced; Details Here