#K51702. Minimum Operations to Achieve Target Sum

    ID: 29146 Type: Default 1000ms 256MiB

Minimum Operations to Achieve Target Sum

Minimum Operations to Achieve Target Sum

You are given an integer n representing the number of elements in a sequence, and an integer S representing the target sum. You are also given a sequence of n integers.

You can perform the following operations on any element of the sequence:

  • Add 1 to an element.
  • Subtract 1 from an element.

Your task is to find the minimum number of operations required so that the sum of the sequence becomes exactly S. If it is not possible to achieve S, output -1.

Note: The maximum adjustment possible per element is assumed to be \(10^6\), therefore the total possible change is bounded by \(n \times 10^6\).

inputFormat

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

N S
a1 a2 ... aN

Here, the first line contains two integers N and S. The second line contains N integers representing the elements of the sequence.

outputFormat

Output the minimum number of operations required to make the sum of the sequence exactly S. If it is impossible, output -1. The output should be printed to standard output (stdout).

## sample
3 15
5 5 5
0