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 1196. History Exam

how to prevent Time limit exceeded? Please proof read my program...
Posted by Henrywong 9 Dec 2006 18:24
var
n,m,i,j,count:longint;
teach:array [1..15000] of int64;
stud:array[1..1000000] of int64;

begin
  readln(n);
  for i:=1 to n do
  begin
    readln(teach[i]);
  end;
  readln(m);
  for i:=1 to m do
  begin
    readln(stud[i]);
     if (stud[i]>=teach[1]) and (stud[i]<=teach[n]) then
     begin
      for j:=1 to n do
      begin
        if stud[i]=teach[j] then
        begin
          count:=count+1;
          break;
        end;
        if stud[i]<teach[j] then
          break;
      end;
     end;
  end;
  writeln(count);
end.
Please tell me how to prevent time limit exceeded
Re: how to prevent Time limit exceeded? Please proof read my program...
Posted by KIRILL(ArcSTU) 9 Dec 2006 19:57
Use binary search