K - Fence Poster Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 466 点

問題文

高橋君の家の庭には、N 枚の板が下端を揃えて隙間なく横一列に並んだフェンスがあります。

左から i 番目 (1 \le i \le N) の板の横幅は 1、高さは A_i です。

高橋君は、このフェンスからはみ出さないように長方形のポスターを 1 枚貼りたいと考えています。

具体的には、以下の条件を満たすようにポスターを貼ることにしました。

  • 連続する板の区間 [L, R] (1 \le L \le R \le N) および正の整数 H (1 \le H \le \min_{L \le i \le R} A_i) を選ぶ。
  • 選んだ区間に、横幅 R - L + 1、高さ H の長方形のポスターを貼る。このとき、ポスターの面積は (R - L + 1) \times H となる。

高橋君は、面積が S 以上であるようなポスターを貼りたいと考えています。

条件を満たすポスターの貼り方が存在するか判定し、存在するならば、ポスターの横幅 R - L + 1 として考えられる最小値を出力してください。

条件を満たす貼り方が存在しない場合は、代わりに -1 を出力してください。

制約

  • 1 \le N \le 5 \times 10^5
  • 1 \le S \le 5 \times 10^{14}
  • 1 \le A_i \le 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N S
A_1 A_2 \dots A_N

出力

面積が S 以上となるポスターの横幅 R - L + 1 の最小値を 1 行で出力してください。そのような選び方が存在しない場合は、-1 を出力してください。


入力例 1

5 8
2 4 4 3 1

出力例 1

2

入力例 2

4 20
3 2 4 2

出力例 2

-1

入力例 3

10 15
3 5 2 7 6 8 4 2 1 5

出力例 3

3

入力例 4

24 2500000000
300000000 450000000 200000000 800000000 750000000 700000000 720000000 500000000 100000000 600000000 650000000 600000000 400000000 350000000 800000000 700000000 200000000 500000000 550000000 500000000 600000000 400000000 300000000 100000000

出力例 4

4

入力例 5

1 1000000000
1000000000

出力例 5

1

Score : 466 pts

Problem Statement

In Takahashi's garden, there is a fence consisting of N boards arranged in a row from left to right without any gaps, with their bottom edges aligned.

The i-th board from the left (1 \le i \le N) has a width of 1 and a height of A_i.

Takahashi wants to put up a single rectangular poster without it extending beyond the fence.

Specifically, he decides to place the poster such that the following conditions are satisfied:

  • Choose a contiguous range of boards [L, R] (1 \le L \le R \le N) and a positive integer H (1 \le H \le \min_{L \le i \le R} A_i).
  • Place a rectangular poster of width R - L + 1 and height H over the chosen range. The area of the poster will be (R - L + 1) \times H.

Takahashi wants to place a poster with an area of at least S.

Determine whether there is a way to place a poster that satisfies the conditions. If it exists, print the minimum possible width R - L + 1 of the poster.

If no such placement exists, print -1 instead.

Constraints

  • 1 \le N \le 5 \times 10^5
  • 1 \le S \le 5 \times 10^{14}
  • 1 \le A_i \le 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N S
A_1 A_2 \dots A_N

Output

Print the minimum possible width R - L + 1 of a poster with an area of at least S in a single line. If no such placement exists, print -1.


Sample Input 1

5 8
2 4 4 3 1

Sample Output 1

2

Sample Input 2

4 20
3 2 4 2

Sample Output 2

-1

Sample Input 3

10 15
3 5 2 7 6 8 4 2 1 5

Sample Output 3

3

Sample Input 4

24 2500000000
300000000 450000000 200000000 800000000 750000000 700000000 720000000 500000000 100000000 600000000 650000000 600000000 400000000 350000000 800000000 700000000 200000000 500000000 550000000 500000000 600000000 400000000 300000000 100000000

Sample Output 4

4

Sample Input 5

1 1000000000
1000000000

Sample Output 5

1