#C8367. Minimum Operations to Reach Target Sum

    ID: 52341 Type: Default 1000ms 256MiB

Minimum Operations to Reach Target Sum

Minimum Operations to Reach Target Sum

You are given a target sum T and a sequence of n integers. In a single operation, you can increment or decrement any element of the sequence by 1. Your task is to determine the minimum number of operations required to adjust the sum of the sequence so that it becomes as close as possible to the target value T.

The minimum number of operations is given by the formula: $$\text{operations} = |S - T|$$ where $$S$$ is the sum of the given sequence.

inputFormat

The input is given via stdin and consists of:

  • A line containing two integers n and T, where n is the number of elements in the sequence and T is the target sum.
  • If n > 0, a second line with n space-separated integers representing the sequence. If n is 0, the sequence is considered empty.

outputFormat

Output a single integer to stdout representing the minimum number of operations required to make the sum of the sequence as close as possible to the target T.

## sample
3 10
1 2 3
4