#C663. Smallest Enclosing Segment Length

    ID: 50411 Type: Default 1000ms 256MiB

Smallest Enclosing Segment Length

Smallest Enclosing Segment Length

You are given a sequence of segments. For each test case, you are provided with an integer N (where \(1 \le N \le 1000\)) representing the number of segments, followed by a line containing N integers \(L_i\) (with \(1 \le L_i \le 1000\)), each representing the length of a segment. Your task is to compute the smallest possible length of an enclosing segment that can cover all the given segments when placed end-to-end.

The answer is simply the sum of the lengths of all provided segments, i.e.,

[ S = \sum_{i=1}^{N} L_i ]

The input terminates when a test case with N = 0 is encountered.

inputFormat

The input consists of multiple test cases. For each test case:

  • The first line contains an integer N (\(1 \le N \le 1000\)), the number of segments.
  • The second line contains N space-separated integers \(L_1, L_2, \dots, L_N\), where \(1 \le L_i \le 1000\).

The input is terminated by a line containing a single 0, which should not be processed.

outputFormat

For each test case, output a single line containing the sum of the segment lengths, which represents the smallest enclosing segment length.

## sample
3
1 2 3
0
6