Maximum Force(Contest)
Maximum Force easy Time Limit: 2 sec Memory Limit: 128000 kB
PreviousMaximizing Difference(Contest)NextLongest subarray not having more than K distinct elements(Contest)
Last updated
Maximum Force easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
Note: Elements are not needed to be continuous. Input The first line of the input contains two integers denoting n and k. The next line contains n integers denoting elements of the array.
Constraints: 1 < = k < = n < = 1000 -10^7 <= A[i] <= 10^7 Output Output the maximum force. Example Sample Input 1: 4 4 1 2 3 4
Sample Output 1: 30
Sample Input 2: 2 1 1 10
Sample Output 2: 100
Explanation: Force = 11 + 22 + 33 + 44 = 30
link: