#Lutece1557. Minimum C0st
Minimum C0st
Migrated from Lutece 1557 Minimum C0st
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
There are numbers where the is .
In order to make the sum of them changed to , you can make some numbers increased by one or decreased by one.
But you should spend dollars to increase or decreased by one, and the new should satisfies .
Any number can be operated any times. What's the minimum cost to make the sum of all numbers changed to ?
Input
The first line contains two integers ,
Next lines each line contains four integers .
$1\leq N\leq 1000, 1\leq S\leq 10^6, 1\leq C_i\leq 1000, 0\leq L_i\leq A_i\leq R_i\leq 1000$
Output
If there is no solutions, print impossible
.
Otherwise, print one integer indicates the minimum cost to make the sum of all numbers changed to .
Samples
3 6
1 1 1 3
1 2 1 3
1 3 1 3
4
Resources
The 15th UESTC Programming Contest Preliminary