#C6425. Longest Feeding Sequence
Longest Feeding Sequence
Longest Feeding Sequence
You are given a series of feeding records for various animals. Each record contains an index, an animal name, and a food type. Your task is to determine the longest sequence of consecutive feedings in which the same animal was fed the same food. If there are no feeding records, output 0.
More formally, let the feeding records be represented as tuples \((i, animal, food)\) for \(i=1,2,\dots,n\). You need to find the maximum length \(L\) such that there exists some contiguous segment of the records in which every record has identical \(animal\) and \(food\) values.
Example: Consider the feeding records:
[ (1, \text{Rex}, \text{bones}),\ (2, \text{Rex}, \text{bones}),\ (3, \text{Rex}, \text{meat}) ]
The longest feeding sequence is 2 because the first two records form a consecutive sequence where Rex is fed bones.
inputFormat
The input is given via standard input (stdin) with the following format:
- The first line contains a single integer \(n\), the number of feeding records.
- Each of the next \(n\) lines contains three values separated by spaces: an integer (the record index), a string representing the animal's name, and a string representing the food type.
outputFormat
Output via standard output (stdout) a single integer representing the length of the longest consecutive feeding sequence where the same animal is fed the same food.
## sample5
1 Rex bones
2 Rex bones
3 Rex meat
4 Rex meat
5 Rex meat
3