PROFESOR

PROFESOR

Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 37 Tried: 89

Submit

Status

Best Solution

Back

Description

 


In a long classroom, N desks are arranged in a single row, with two students sitting at each desk. Students are cranky because they are about to have an art class, and their professor is planning to examine them.

Each student has studied art, but only to a certain level. The old professor can tell by the looks on their faces just how much they have studied. The professor, being an artist, uses a different coloured pencil for each grade. Unfortunately, today he brought only one pencil.

In order to make the examination seem fair, he wants to choose two desks and question one student from each desk positioned between the two desks he has chosen (including the chosen desks). It is important that all examined students deserve the same grades, so he can write them down using his only pencil.

The professor wants to know the maximum number of students he can examine this way, as well as which grade the students will get.


 

Input

 


The first line of input contains a single integer N (1 <= N <= 100 000).

Each of the following N rows contains two integers: Ai and Bi, grades deserved by students sitting at desk i (1 <= Ai, Bi <= 5).

 

Output

 


The first and only line of output must contain two numbers separated by a single space: the maximum number of students the professor can examine and the grade those students will get.

If there are multiple solutions possible, output the one with the smallest grade.

 

Sample Input

 


Input 1
1
1 5

Input 2
3
3 5
4 5
1 3

Input 3
4
2 1
3 2
5 3
2 5


 

Sample Output

 


Output 1
1 1

Output 2
2 5

Output 3
2 2

链接:http://acm.uestc.edu.cn/problem.php?pid=1569

 

3个注意地方:1.___     ______即中间隔了一段再比较2.一个桌子有两个相同的成绩只能从中选一个3.选的要连续

#include <stdio.h>
int A[200000],B[200000];
int main( )
{
  int n;
  while(~scanf("%d",&n))
  {
    for( int i=1;i<=n;i++)
    {
   scanf("%d%d",&A[i],&B[i]);
    }
    int x,y;
    int len;
    x=-1;
    for( int i=1;i<=5;i++)
    {
    len=0;
    for( int j=1;j<=n;j++)
    {
     if(A[j]==i||B[j]==i) ++len;
  else
  {
       
         len=0;
  }
  if(len>x) x=len,y=i;
      }
    
    }
    printf("%d %d\n",x,y);
  }
  return 0;
}

 

posted @ 2012-10-08 21:22  jiai  Views(260)  Comments(0Edit  收藏  举报