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 1021. Sacrament of the Sum

Binary search
Posted by Max 7 Oct 2008 16:35
   readln(N1);
   for I:=0 to N1-1 do
   readln(A1[I]);


   readln(N2);
   for I:=0 to N2-1 do
     readln(A2[I]);

    for I:=0 to N1 -1 do
    begin
     k:=10000-A1[I];
     l:=0;
     u:=N2-1;
     m:=1;
     while ((m<=N2) and (m>0)) do
     begin
       m:=(l+u) div 2;
       if k < A2[m] then
         l:=m+1
       else if k>A2[m] then
         u:=m-1
       else
       begin
       write('YES');
       halt;
       end;

     end;
    end;
    write('NO');

"Time limit exceeded"

чем плох мой алгоритм?