Bitcoin transactions are made up of 1 or inputs and 1 or more outputs. Inputs are discrete amounts of bitcoin that you control. Outputs are where you want to send the bitcoin (and exactly how much). The sum of all the outputs must be less than or equal to the sum of all the inputs (otherwise you could create money from nothing).
When creating a bitcoin transaction, you have a list of eligible inputs to source and need to pick which you want to use. It is not possible to "partially source" an input, but if you selected too much money you can create something called a "change output" which allows you to sending money back to yourself. Note: you can not send yourself less than 100000 amount.
Few defintions for a transaction:
"Mining fee" is defined as the SUM(chosen input amounts) - SUM(chosen output amounts) which is effectively how much money the transaction "destroys".
"Transaction size" is defined as: 148 * COUNT(chosen inputs) + 10 + 34 * COUNT(chosen outputs)
"FeeRate" is defined as "Mining fee" / "Transaction size"
For a transaction to be valid, it needs to have at least a certain feeRate. If the transaction pays more fees than is required, the amount paid in excess is known as "miningSacrifice" (which is the absolute amount of money you wasted by over paying).
--
The goal of the problem is to minimize the "cost". The cost of a transaction is simply:
$INPUT_COST * COUNT(chosen inputs) + ($CHANGE_COST if the transaction uses a change output) + miningSacrifice