#C4751. Minimum Total Expense

    ID: 48324 Type: Default 1000ms 256MiB

Minimum Total Expense

Minimum Total Expense

A farmer has a line of ( n ) fields. For each field ( i ), there is an associated plowing cost ( cost_i ) and an irrelevant width ( width_i ) (provided for historical reasons). The farmer wishes to plow a contiguous non-empty segment of these fields. However, every time the farmer starts plowing a new contiguous segment, a fixed overhead cost of ( c ) is applied.

The task is to choose a contiguous segment of fields such that the total expense is minimized. The total expense is computed as the sum of the costs of the fields in the segment plus one overhead cost ( c ) (applied only once for that segment).

Formally, if you choose fields from index ( l ) to ( r ) (1-based indices), the total expense is: [ \text{Expense} = c + \sum_{i=l}^{r} cost_i ] Your goal is to determine the minimum possible total expense over all possible non-empty segments.

Note: The widths array is provided but is not used in the expense calculation.

inputFormat

The input is read from standard input and has the following format:

  • The first line contains two integers \( n \) and \( c \) separated by a space, where \( n \) is the number of fields and \( c \) is the fixed overhead cost.
  • The second line contains \( n \) space-separated integers, representing the widths of the fields. (This array is not used in the calculation.)
  • The third line contains \( n \) space-separated integers, representing the plowing costs of the fields.

outputFormat

Output to standard output a single integer representing the minimum total expense to plow a contiguous segment of fields.## sample

4 10
3 1 4 2
5 2 7 3
12