#P1711. [USACO18FEB] Taming the Herd B

[USACO18FEB] Taming the Herd B

Problem Description

Early one morning, Farmer John was woken up by the sound of cracking wood. It was the cows again—they escaped from the barn!

Farmer John is tired of the cows escaping in the morning, and he has had enough: it is time to take tough measures. He nailed a counter to the wall of the barn to track how many days have passed since the last escape. So if an escape happens on some morning, the counter is 00 on that day; if the most recent escape was 33 days ago, the counter reads 33. Farmer John carefully recorded the counter reading for every day.

By the end of the year, Farmer John wants to do some statistics. He says, you cows will pay the price! However, unexpectedly, some entries in his records were lost!

Farmer John is sure that he started recording on a day when an escape happened. Please help him determine, among all escape event sequences consistent with the remaining record entries, based on the time covered by the records, the minimum and maximum possible number of escapes.

Input Format

The first line contains an integer NN (1N1001\le N\le 100), the number of days that have passed since Farmer John started counting using the escape counter.

The second line contains NN space-separated integers. The ii-th integer is 1-1, meaning the record for day ii is missing, or a non-negative integer aia_i (not exceeding 100100), meaning that on day ii the counter value was aia_i.

Output Format

If there is no event sequence consistent with Farmer John’s remaining records and the fact that the cows escaped on the morning of day 11, output a single integer 1-1. Otherwise, output two space-separated integers mm and MM, where mm is the minimum number of escapes among all event sequences, and MM is the maximum number of escapes.

4
-1 -1 -1 1
2 3

Hint

In this sample, we can infer that an escape must have happened on day 33. We already know that an escape also happened on day 11, so the only remaining uncertainty is whether an escape happened on day 22. Therefore, the total number of escapes is between 22 and 33.

Translated by ChatGPT 5