Under construction

Still being built. Things may change

Optimizing the Matrix

Interview

Time limit1sMemory limit1024 MB

Summary
Pick one node and spread its action k nodes in each direction, zeroing the reached nodes and multiplying the chosen one. Find the maximum total importance.
Level

Easy3 of 10

Topics
Prefix sum, Implementation
Solved
No attempts yet

Problem

The AI that keeps the Matrix running is a complex system, so the Architect decided to try optimizing it.

The system can be modeled as nn nodes connected in a sequence. Each node has a special characteristic wiw_i, its computational importance.

The Architect picks one node and spreads its action to kk neighboring nodes in each direction. If a direction has fewer than kk nodes, the action spreads to all of them. Let dd be the total number of nodes the action reaches. Then the computational importance of the chosen node becomes (1+d)⋅wi(1 + d) \cdot w_i, and the nodes reached by the action get importance 00.

Help the Architect find the maximum total computational importance of the system that can be obtained by performing this action.

Input

The first line contains two integers nn and kk, the number of computational nodes and the number of nodes the action spreads to in one direction (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 0≤k≤2⋅1050 \le k \le 2 \cdot 10^5).

The second line contains nn positive integers w1,w2,…,wnw_1, w_2, \dots, w_n separated by spaces, the computational importance of each node (1≤wi≤5⋅1051 \le w_i \le 5 \cdot 10^5).

Output

Print one integer, the maximum total computational importance of the system that can be obtained.

Examples2

  1. Example 1

    Input
    3 1
    1 3 2
    
    Expected output
    9
    
  2. Example 2

    Input
    5 1
    1 5 3 2 4
    
    Expected output
    21