Under construction

Still being built. Things may change

Search Game

Time limit2sMemory limit1024 MB

Summary
Find the query strategy that minimizes the expected score of locating a hidden X from 1 to N, where each query of up to K numbers reports how many are below X.
Level

Medium7 of 10

Topics
Dynamic programming, Prefix sum
Solved
No attempts yet

Problem

Jonghyeon, a student at KSA, made a search game to boost virtual currency trading at the autumn school festival. In the search game, an integer XX (1≤X≤N1 \le X \le N) is fixed before the game starts, and you find its value by asking the right questions. In each question, the player enters at most KK distinct positive integers not greater than NN. If XX is among the entered values, the game ends. Otherwise, the player receives the number of entered integers that are less than XX. This process repeats until the game ends. If the game takes nn questions, the final score is (K+1)n−1(K+1)^{n-1} points. You are a hacker who wants to earn virtual currency and take all the snacks and souvenirs from Jonghyeon. Find the strategy that minimizes the expected score of the search game, and print that expected value. The value XX is fixed before the player enters anything, and the probability that XX is ii is PiP1+⋯+PN\frac{P_i}{P_1 + \cdots + P_N}.

Input

The first line contains two integers NN and KK, separated by a space. The second line contains NN integers P1,P2,⋯ ,PNP_1, P_2, \cdots, P_N, separated by spaces.

Output

Print the expected score under the optimal strategy, multiplied by (P1+P2+⋯+PN)(P_1 + P_2 + \cdots + P_N).

Constraints

1≤N≤15001\leq N\leq 1500, 1≤K≤51\leq K \leq 5, 1≤Pi≤10001\leq P_i\leq 1000.

Examples4

  1. Example 1

    Input
    5 1
    1 1 1 1 1
    
    Expected output
    13
    
  2. Example 2

    Input
    5 2
    1 1 1 1 1
    
    Expected output
    11
    
  3. Example 3

    Input
    4 1
    4 3 2 10
    
    Expected output
    39
    
  4. Example 4

    Input
    4 1
    4 3 2 12
    
    Expected output
    42