Double Beauty
Practice
5 (3 votes)
Greedy algorithms
Basics of greedy algorithms
Sorting
Algorithms
Merge sort
Problem
49% Success 1297 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of length \(N\). You can select \(K\) distinct indexes and double the element in them.
The beauty of the array is the sum of any subarray of length \(K\). Find the maximum beauty over all permutations of array \(A\).
Input Format:
- The first line contains an integer \(T\), denoting the number of test cases.
- The first line of each test case contains two integers \(N\) and \(K\) respectively.
- The second line of each test case contains \(N\) space-separated integers, denoting the elements of the array.
Output Format:
For each test case, print the maximum beauty over all permutations of \(A\).
Constraints:
\(1 <= T <= 10\)
\(1 <= K <= N <= 10^5\)
\(1 <= A[i] <= 10^3\)
Submissions
Please login to view your submissions
Similar Problems
1.Subxor
Points:10
48 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Points:10
4 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:10
11 votes
Tags:
HashingGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Editorial