#P6300. Reassembling Wooden Sticks

    ID: 19518 Type: Default 1000ms 256MiB

Reassembling Wooden Sticks

Reassembling Wooden Sticks

Daniel13265 once had several identical wooden sticks. He randomly cut each stick into two segments such that the length of each segment does not exceed \( m \). Later, he lost some segments and forgot the original number of sticks as well as their lengths. Now, with the remaining segments, he wishes to reassemble as many wooden sticks as possible, where every reassembled stick has the same length.

Given the lengths of the remaining segments, your task is to determine two values:

  • The maximum number of sticks that can be reassembled (each stick is formed by concatenating one or more segments, and each segment can be used at most once).
  • The minimum possible stick length \( L \) that yields this maximum number of sticks.
  • Note that \( L \) must be at least as long as the longest segment. The segments may be combined in arbitrary order, and not all segments need to be used.

    Input Example:
    For instance, if the remaining segments are 1, 2, 3, 4, one valid reassembly is to form two sticks: one of length \( 4 \) (using the segment \( 4 \) or \( 1+3 \)) and another of the same length \( 4 \) (using the remaining segments). Thus, the answer would be 2 4.

    inputFormat

    The input begins with a single integer \( n \) (the number of remaining segments). The next line contains \( n \) space-separated positive integers, which are the lengths of these segments.

    Constraints: Each segment's length is \(\le m\) (\( m \) is a given constant though not provided in the input) and \( L \) (the target reassembled stick length) must be at least the maximum segment length.

    outputFormat

    Output two space‐separated integers: the maximum number of sticks that can be reassembled and the minimum stick length \( L \) for which this maximum is achieved.

    sample

    4
    1 2 3 4
    2 4