#K44697. Longest Pill Duration

    ID: 27589 Type: Default 1000ms 256MiB

Longest Pill Duration

Longest Pill Duration

You are given several datasets. In each dataset, the first number is an integer n representing the number of pills, followed by a line containing n integers which represent the individual time windows for taking each pill.

Your task is to calculate the longest possible duration to take all the pills in sequence by summing these time windows. In other words, if the time windows are \(t_1, t_2, \dots, t_n\), then the answer is \(\sum_{i=1}^{n} t_i\).

The input consists of multiple datasets and terminates when a dataset beginning with 0 is encountered. For each dataset, output the computed duration on a new line.

inputFormat

The input is read from stdin and consists of multiple datasets. Each dataset is formatted as follows:

  • The first line contains an integer n which denotes the number of pills.
  • If n is greater than 0, the second line contains n space-separated integers representing the time windows for the pills.
  • The end of input is indicated by a line with a single 0.

For example:

3
5 10 20
4
3 5 8 13
1
7
0

outputFormat

For each dataset (except the termination signal), output a single line containing a single integer representing the longest possible duration to take all the pills (i.e., the sum of the time windows).

For the sample input above, the output would be:

35
29
7
## sample
3
5 10 20
4
3 5 8 13
1
7
0
35

29 7

</p>