#C1233. Maximize Warehouse Items

    ID: 41745 Type: Default 1000ms 256MiB

Maximize Warehouse Items

Maximize Warehouse Items

You are given n types of items and a warehouse that can store at most C items. For each type, you know the number of items available. Your task is to determine the maximum number of items that can be stored in the warehouse without exceeding its capacity.

The solution is simple: you can only store as many items as the warehouse capacity allows, but if the total number of items is less than or equal to the capacity, then you can store all of them. In mathematical terms, if S is the sum of items, then the answer is \( \min(S, C) \).

inputFormat

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

  • The first line contains two integers n and C where n (1 ≤ n ≤ 105) is the number of item types and C (0 ≤ C ≤ 109) is the warehouse capacity.
  • The second line contains n space-separated integers, with each integer representing the number of items of that type. Each integer is non-negative and does not exceed 109.

outputFormat

Output a single integer representing the maximum number of items that can be stored in the warehouse.

## sample
5 10
2 3 1 4 6
10