#P6087. Maximizing the Beauty of Gift Selection

    ID: 19311 Type: Default 1000ms 256MiB

Maximizing the Beauty of Gift Selection

Maximizing the Beauty of Gift Selection

You are given a row of N gifts, where the i-th gift (1 ≤ i ≤ N) has a positive integer beauty Ai. Your task is to select a contiguous segment of gifts, with indices from i to j (1 ≤ i ≤ j ≤ N), such that the number of gifts chosen is at least L and at most R (i.e. j - i + 1 ∈ [L, R]).

The beauty score of a chosen segment is defined as $$ \frac{M(i,j)-m(i,j)}{j-i+K} $$ where

  • M(i,j) = \(\max\{A_i, A_{i+1}, \ldots, A_j\}\)
  • m(i,j) = \(\min\{A_i, A_{i+1}, \ldots, A_j\}\)
  • K is a given positive integer.
Your goal is to compute the maximum beauty score possible by selecting an appropriate contiguous segment.

Input Format:

  • The first line contains four space-separated integers: N, K, L, and R.
  • The second line contains N space-separated positive integers representing the beauty values A1, A2, \ldots, AN.

Output Format:

  • Output a single line with a floating point number, which is the maximum beauty score. Print the result rounded to 6 decimal places.

Constraints:

  • 1 ≤ N ≤ (constraints not specified, assume small enough for brute force)
  • 1 ≤ Ai ≤ 109
  • 1 ≤ K, L, R ≤ N and L ≤ R

inputFormat

The input consists of two lines:

  1. First line: Four integers N, K, L, and R separated by spaces.
  2. Second line: N integers representing the beauty values of the gifts.

outputFormat

Output a single floating point number: the maximum computed beauty score, rounded to 6 decimal places.

sample

3 1 1 3
1 2 3
0.666667