E - Placement of Street Lights Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433 点

問題文

高橋君の住む町には、一本の長い直線道路があります。道路沿いには N 個の区画が一列に並んでおり、左から順に区画 1, 2, \ldots, N と番号が振られています。

各区画 i には、夜間の危険度を表す値 A_i が定められています。これは、その区画の交通量や治安状況などから算出されたものです。

町の予算では、ちょうど K 台の街灯を設置することができます。街灯は N 個の区画のうち任意の K 個に 1 台ずつ設置できます(同じ区画に複数台は設置できません)。

街灯が設置された区画の最終的な危険度は 0 になります。街灯が設置されていない区画 j の最終的な危険度は、以下のように決まります:

  • 区画 j から最も近い街灯が設置された区画までの距離を d_j とする(距離は区画番号の差の絶対値)。
  • 区画 j の最終的な危険度は A_j \times d_j である。

すなわち、街灯から離れるほど照明の効果が弱まり、元の危険度に距離を掛けた値がその区画に残る危険度となります。

高橋君は、全区画の最終的な危険度の最大値をできるだけ小さくしたいと考えています。

K 台の街灯を最適に配置したとき、全区画の最終的な危険度の最大値として達成可能な最小値を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq N
  • 0 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、区画の数を表す N と、街灯の台数を表す K が、スペース区切りで与えられる。
  • 2 行目には、各区画の危険度を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

全区画の最終的な危険度の最大値として達成可能な最小値を 1 行で出力せよ。


入力例 1

5 2
3 1 4 1 5

出力例 1

4

入力例 2

4 1
2 0 3 1

出力例 2

3

入力例 3

12 4
8 1 6 0 10 3 7 2 9 4 5 11

出力例 3

9

入力例 4

30 7
12 5 20 0 7 15 3 25 8 1 30 6 14 2 18 10 4 22 9 13 0 16 11 27 5 19 2 24 7 21

出力例 4

36

入力例 5

1 1
1000000000

出力例 5

0

Score : 433 pts

Problem Statement

In the town where Takahashi lives, there is a single long straight road. Along the road, there are N sections arranged in a line, numbered 1, 2, \ldots, N from left to right.

For each section i, a value A_i representing the level of danger at night is determined. This is calculated based on factors such as traffic volume and public safety in that section.

The town's budget allows for exactly K streetlights to be installed. A streetlight can be installed in any K distinct sections out of the N sections (at most one streetlight per section).

The final danger level of a section where a streetlight is installed becomes 0. The final danger level of a section j where no streetlight is installed is determined as follows:

  • Let d_j be the distance from section j to the nearest section with a streetlight (the distance is the absolute difference between their section numbers).
  • The final danger level of section j is A_j \times d_j.

In other words, the further a section is from a streetlight, the weaker the lighting effect becomes, and the remaining danger level of that section is its original danger level multiplied by the distance.

Takahashi wants to make the maximum value of the final danger levels among all sections as small as possible.

Find the minimum possible maximum value of the final danger levels among all sections when K streetlights are optimally placed.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq N
  • 0 \leq A_i \leq 10^9
  • All input values are integers.

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains N, the number of sections, and K, the number of streetlights, separated by a space.
  • The second line contains A_1, A_2, \ldots, A_N, representing the danger level of each section, separated by spaces.

Output

Print the minimum possible maximum value of the final danger levels among all sections in a single line.


Sample Input 1

5 2
3 1 4 1 5

Sample Output 1

4

Sample Input 2

4 1
2 0 3 1

Sample Output 2

3

Sample Input 3

12 4
8 1 6 0 10 3 7 2 9 4 5 11

Sample Output 3

9

Sample Input 4

30 7
12 5 20 0 7 15 3 25 8 1 30 6 14 2 18 10 4 22 9 13 0 16 11 27 5 19 2 24 7 21

Sample Output 4

36

Sample Input 5

1 1
1000000000

Sample Output 5

0