#K3841. Optimal Pen Dimensions
Optimal Pen Dimensions
Optimal Pen Dimensions
You are given a total length of fencing material L. Your task is to determine the dimensions of a rectangular pen (length and width) that maximize the enclosed area. The pen is constructed using exactly L units of fencing where the sum of twice the length and twice the width equals L. Note that the fencing is used in integer units only.
Mathematically, if the length and width of the pen are denoted by \(l\) and \(w\) respectively, then they satisfy:
\(2l + 2w = L\)
Your goal is to choose integers \(l\) and \(w\) such that the area \(A = l \times w\) is maximized. It can be shown that the maximum area is achieved when \(l\) and \(w\) are as equal as possible.
For example:
- If
L = 20
, one optimal solution isl = 5
andw = 5
, resulting in an area of 25. - If
L = 18
, one valid solution isl = 5
andw = 4
(or vice versa), yielding an area of 20.
inputFormat
The input consists of a single integer L representing the total length of the fencing material.
Input Format:
L
outputFormat
Output two space-separated integers representing the optimal dimensions of the pen (length and width) that maximize the enclosed area. If there are two valid solutions, output the one computed by the specified algorithm.
Output Format:
length width## sample
20
5 5