#P6444. Art Class Fair Check
Art Class Fair Check
Art Class Fair Check
In a long classroom, there are n desks arranged in a row, and each desk seats exactly 2 students. The professor is about to conduct an art check because the students are anxious about their upcoming art class.
Having observed that every student has acquired some level of art knowledge, the professor can determine a student's art score by his facial expression. However, he only has one colored pencil with which he can write a single score.
To make the exam appear fair, he intends to choose 2 desks such that, from every desk in the contiguous segment between these two desks (including the chosen endpoints), he questions exactly one student. Important: All selected students must have the same score. In other words, if the common score is denoted by \(x\), then for every desk in the chosen segment, at least one of the two students must have an art score equal to \(x\).
You are given the art scores of the two students sitting at each desk. Your task is to determine the maximum number of students (i.e. the length of a contiguous block of desks, with length at least 2) that the professor can examine using the method described above, and the corresponding common art score \(x\) that they all share. If no contiguous segment of at least 2 desks satisfies the condition for any art score, output 0 0.
The problem can be formally stated as follows:
Given an integer \(n\) (\(n \ge 2\)) and \(n\) pairs of integers representing the art scores of the two students at each desk, find a value \(x\) and a contiguous segment of desks \([L,R]\) (with \(R - L + 1 \ge 2\)) such that for every desk \(i\) in the segment, at least one student has an art score equal to \(x\). Among all such possibilities, choose the one with the maximum number of desks. If there are multiple common scores yielding the maximum segment length, output the one with the smallest art score.
Note: If no valid segment of at least 2 desks exists, output 0 0.
inputFormat
The first line contains an integer \(n\) (\(n \ge 2\)), representing the number of desks in the classroom.
Then \(n\) lines follow. Each of these \(n\) lines contains two integers, representing the art scores of the two students sitting at that desk.
It is guaranteed that the input is valid.
outputFormat
Output two integers separated by a space. The first integer is the maximum number of students (i.e., the length of the contiguous segment of desks) the professor can examine, and the second integer is the common art score \(x\) that the selected students will receive. If no contiguous segment of at least 2 desks satisfies the condition, output 0 0.
sample
5
1 2
3 2
2 4
2 2
5 2
5 2