ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1090. In the Army Now

What's wrong with my program?I think there is no wrong.
Posted by t 10 Mar 2007 13:33
Program p1090;

Const
  Maxn=12000;

Var
  Ans,good,p,n,m,i,j,k,fin:Longint;
  A:array[0..Maxn] of Longint;
  L:array[0..Maxn] of Longint;

Procedure Find(left,right,p:Longint);
Var
  mid:Longint;
Begin
  If left>right Then Exit;
  If Left=Right Then
    Begin
      If (L[left]<p) And (L[left]<>0) And (Left>good) Then Good:=left;
      Exit;
    End;
  mid:=(left+right) div 2;
  If (L[mid]<P) And (L[mid]<>0) And (mid>good) Then
    Begin
      Good:=mid;Find(mid+1,right,p);
    End
  Else Find(left,mid-1,p);
End;

Begin
    Readln(N,M);
  Fin:=Maxlongint div 2;
  For i:=1 to m Do
    Begin
      For j:=1 to n Do
        Read(A[j]);
      Readln;
      Fillchar(L,sizeof(L),0);
      Ans:=0;
      For j:=1 to n Do
        Begin
          Good:=0;
          Find(1,Ans,A[j]);
          If good+1>Ans Then Ans:=good+1;
          If (L[good+1]=0) or (L[good+1]>A[j]) Then L[good+1]:=A[j];
        End;
      If Ans<fin Then
        Begin
          Fin:=Ans;P:=I;
        End;
    End;
  WRiteln(p);
  End.