Problem D
Downpayment
Large houses cost a lot of money. Typically, a loan is required in order to finance the investment. The credit institutions provide a plentitude of different mortgage alternatives which come with diferent interest rates. Each alternative has a binding time, during which you may not change institution or terms. After this period, you may change alternative, at a penalty cost, or stay with that alternative for another full period. The tricky thing is that the interest changes over time, even within each alternative.
In this problem, we make the absurd assumption that a crystal ball is at your disposal. That is, you know, in advance, what the different interest rates for all institutions are going to be at all times. Given this information, your task is to come up with a plan for the payments which minimizes the absolute amount of money paid over the entire period.
For each month, the following items are added to the debt:
-
Any possible penalties for changing the terms. For the first month, you may choose any alternative without penalty.
-
The interest for the dept, including the penalty.
After these items has been added, the amount is rounded to two decimals towards zero. Then, a fixed amount is paid, i.e., the debt is reduced by this amount. However, if the debt is less than the fixed amount, only the remaining debt is paid and the loan is fully paid. You do not have to pay any penalty if the binding time for your current terms is not at end when the loan is paid.
Input
On the first line of input there is one integer,
You may assume that the input is such that numerical errors
in your computation smaller than
Output
Start each test case with a line stating the test case, as
this: “Test case
Sample Input 1 | Sample Output 1 |
---|---|
2 1 200.1 100 1 0 5 3 3 3 3 3 2 300.23 100.17 1 2 0 4 4 0 4 7 15 20 5 3 10 4 10 |
Test case 1 Month 1: Alternative 1 Month 2: Alternative 1 Month 3: Alternative 1 Total: 209.55 Test case 2 Month 1: Alternative 1 Month 2: Alternative 2 Month 3: Alternative 2 Month 4: Alternative 2 Total: 355.05 |