Question: Sprinklr | OA | 2023 | The Minimum Sum
2
Entering edit mode

The Minimum Sum

You are given an array of size n with positive and negative integers. You are also given an Integer x.

You can repeat this process any number of times (>=0).

  • Choose an element from the array and apply this transform, A[i] -> f(A[i] / x) * x, where f(y) returns the largest integer <= y if y >= 0, otherwise the smallest integer>= y.

Note : A[i] / x is a floating-point division.

Your task is to minimize the sum of the final array and print the minimum sum.

Input format

  • The first line contains n and x
  • The next line contains n space-separated integers, where the ith integer corresponds to A[i]

Output format

Print the minimum sum.

1 ≤ n ≤ 106

0 ≤ |A[i]| ≤ 109

1 ≤ x ≤ 109

 

Sample input 

5 1

1 2 3 4 5

Sample output

15

Entering edit mode
0

any other questions ??

ADD REPLYlink 17 months ago
Ramansh Goyal
• 0
0
Entering edit mode

bhai constraint sahi se btao

ADD COMMENTlink 17 months ago sagar . • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts