#P4274. Minimizing Total Lawn Area
Minimizing Total Lawn Area
Minimizing Total Lawn Area
In the 21st century, Little H aspires to be a great mathematician – but first he must "package" himself well. He decides to design his residence in a unique way. Its east‐west length is fixed to 100 Hil (a mysterious unit), with the east and west walls being vertical. The north and south walls are oblique lines with positive slopes \(k_1\) and \(k_2\) respectively. Along the north and south walls (that is, at the corners), a sequence of rectangular lawns is arranged. Each rectangle has its sides parallel to the coordinate axes. The lawns are placed contiguously so that each adjacent pair touches exactly at a point on the wall. The x–coordinate of that touching point (which lies strictly between 0 and 100) is called a division point and must be an integer between 1 and 99 inclusive.
Little H demands that there be exactly \(m\) lawns along the north wall corner and exactly \(n\) lawns along the south wall corner with \(m \le n\). If we denote by \(X_1\) and \(X_2\) the sets of division points used on the north and south walls respectively, then it is required that \(X_1 \subseteq X_2\) (each division point on the north wall appears also on the south wall).
For a wall with a chosen increasing sequence of division points \(P = {p_1, p_2, \dots, p_r}\) (with the endpoints fixed as 0 and 100), the lawns partition the wall into segments with lengths \(d_0 = p_1-0, d_1 = p_2-p_1, \dots, d_{r} = 100 - p_r\). The cost (i.e. area) of the lawns is determined as follows:
- On the north side, no further subdivision is allowed – the total area is simply \[ A_{north} = \frac{(d_0)^2+(d_1)^2+\cdots+(d_{r})^2}{2k_1}. \]
- On the south side, one is allowed to add extra division points. In fact, if the set \(X_1\) chosen for the north wall is fixed, then the south wall must contain all those division points but can also include extra points so that there are exactly \(n\) lawns. In other words, if an interval of length \(L\) (between two consecutive points in \(\{0\}\cup X_1 \cup \{100\}\)) is further subdivided into \(r\) segments (by placing \(r-1\) extra points), then the minimal achievable cost for that interval (by optimally choosing the extra points among integers) is \[ f(L,r) = (r-\rho)\, a^2 + \rho\,(a+1)^2, \quad \text{where } a = \lfloor L/r \rfloor, \; \rho = L \bmod r, \; 1\le r \le L. \] Thus the total cost on the south side is \[ A_{south} = \frac{\sum_{i=0}^{m} f(d_i, r_i)}{2k_2}, \] where the \(r_i\) are positive integers satisfying \(\sum_{i=0}^{m} r_i = n+1\) (since an interval with one segment means no extra division point, and the whole south wall is partitioned into \(n+1\) segments overall).
Your task is to choose the north wall’s division points \(X_1\) (a set of \(m\) integers in \(\{1,2,\dots,99\}\)) together with an optimal extra subdivision of the south side (i.e. choosing how to distribute the extra \(n-m\) points among the \(m+1\) intervals) so that the total cost (which is the total lawn area) given by
[ \text{Total Cost} = \frac{\text{north cost}}{2k_1} + \frac{\text{south cost}}{2k_2} ]
is minimized.
Input
The input consists of one line containing two integers and two real numbers: m n k1 k2 where \(m\) and \(n\) (with \(m \le n\)) denote the number of lawns at the north and south walls respectively, and \(k_1\) and \(k_2\) are the positive slopes.
Output
Output a single real number — the minimized total cost. The answer must be printed with 6 decimal places.
Note: All division points (including any extra ones that may be chosen for the south wall) must be integers between 1 and 99, and the endpoints 0 and 100 are fixed.
inputFormat
A single line containing two integers and two real numbers: m n k1 k2
.
- 1 ≤ m ≤ n ≤ 99
- k1, k2 are positive real numbers.
outputFormat
Output a single real number — the minimum total cost — with 6 decimal places.
sample
1 1 1 1
5000.000000