#P2080. Happy Life with Balanced Affection
Happy Life with Balanced Affection
Happy Life with Balanced Affection
In this problem, two individuals initially have an affection value of 0 towards each other. There are n tasks available, and each task i increases the affection from the first person to the second by ai points and from the second to the first by bi points. The intimacy between them is defined as the sum of their affection values. If their total intimacy reaches at least v, they will get together.
However, their future happiness depends on the absolute difference between their affection values; the smaller the difference, the happier they will be. Your task is to help determine the minimum possible absolute difference between their affection values such that the total intimacy is at least v. If it is impossible to achieve an intimacy of at least v by choosing any subset of tasks, output -1.
Note: Any formulas should be represented in LaTeX format. For example, intimacy is computed as $a+b$ and the difference is $|a-b|$.
inputFormat
The first line contains two integers n and v, representing the number of tasks and the target intimacy value, respectively.
Each of the following n lines contains two integers ai and bi that indicate the change in affection from performing the i-th task.
outputFormat
Output a single integer: the minimum absolute difference between the two affection values, under the condition that their total intimacy is at least v. If it is impossible to meet the intimacy requirement, output -1.
sample
3 5
1 2
2 1
3 1
0
</p>