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 1642. 1D Maze

Please, help me to understand mistake
Posted by Irkutsk STU 2 2 Nov 2008 16:05
My algo:

uses
  SysUtils;

var
   ex: Integer;
   Prep: integer;
   i, k: integer;
   Imposs: boolean = false;
   MinP: integer;
   MaxP: integer;
   fir ,sec: integer;

begin
 //
 Readln( prep, ex );
 MinP:= -1000;
 MaxP:= +1000;
 if Prep > 0 then
  for i:= 1 to prep do begin
   Readln( k );
   if ( k < 0 ) and ( k > MinP ) then MinP:= k;
   if ( k > 0 ) and (k < MaxP ) then MaxP:= k;
   if ( ( ex > 0 ) and ( MaxP < ex ) ) or
      ( ( ex < 0 ) and ( MinP > ex ) ) then Imposs:= true;
  end; // for
 if not Imposs then begin
  if Ex > 0 then begin
   Fir:= Ex;
   Sec:= 2 * Abs( MinP ) + Ex;
  end
  else if Ex < 0 then begin
   Fir:= 2 * MaxP + Abs( Ex );
   Sec:= Abs( Ex );
  end;
 end;
 if not Imposs then Writeln( Fir, ' ', Sec )
 else Writeln( 'Impossible' );
 //
end.

wrong answer in test 1!