#C4433. Calculate Total Duration
Calculate Total Duration
Calculate Total Duration
Given a list of integers representing durations in minutes, some of which may be negative (and should be ignored), compute the total duration by summing only the valid (non-negative) values. Then, convert the total minutes to a duration formatted as DD days, HH:MM
. The conversion is based on the formula:
\(\text{total\_minutes} = \sum_{i} \text{valid\_duration}_i\)
\(\text{days} = \lfloor \text{total\_minutes} / (24 \times 60) \rfloor\)
\(\text{hours} = \lfloor (\text{total\_minutes} \mod (24 \times 60)) / 60 \rfloor\)
\(\text{minutes} = \text{total\_minutes} \mod 60\)
Output the result as a string with two-digit days, hours, and minutes. For example, if the total valid duration is 465 minutes, the output should be "00 days, 07:45".
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains a single integer
n
, representing the number of durations. - The second line contains
n
space-separated integers, each representing a duration in minutes. Negative values should be considered invalid.
outputFormat
Print a single line to stdout representing the total valid duration in the format DD days, HH:MM
.
4
45 120 300 -1
00 days, 07:45