#K41602. Maximum Happiness from Consecutive Stores

    ID: 26902 Type: Default 1000ms 256MiB

Maximum Happiness from Consecutive Stores

Maximum Happiness from Consecutive Stores

You are given (N) stores arranged in a line. Each store (i) is associated with two integers: (S_i) and (L_i). The happiness obtained from the (i)-th store is defined by the formula (P_i = S_i \times L_i). Your task is to pick exactly (K) consecutive stores and maximize the total happiness. That is, you need to compute the maximum sum of (P_i) over any contiguous segment of stores of length (K).

Input Format: The first line contains two integers (N) and (K). This is followed by (N) lines, each containing two integers (S_i) and (L_i) separated by a space.

Output Format: Print a single integer — the maximum total happiness obtainable by choosing exactly (K) consecutive stores.

inputFormat

The input is given via standard input (stdin) and consists of:

  • The first line contains two space-separated integers \(N\) and \(K\).
  • The next \(N\) lines each contain two space-separated integers \(S_i\) and \(L_i\).

outputFormat

The output should be printed to standard output (stdout). Output a single integer that is the maximum total happiness from any segment of \(K\) consecutive stores.

## sample
5 3
3 2
2 1
5 3
4 3
1 2
29

</p>