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 1061. Buffer Manager

Why my prog not AC?
Posted by lyj_george 17 Oct 2002 16:17
const
  max = 100000;
var
  can , find : boolean;
  ch : char;
  o , bh : array [0..max] of longint;
  min , n , k , i , j , rec : longint;
begin
  fillchar(o,sizeof(o),0);
  fillchar(bh,sizeof(bh),0);
  i := 0;
  j := 1;
  can := true;
  readln(n,k);
  if k > n then begin
    writeln(0);
    halt;
  end;
  while not eof(input) do begin
    while not eoln(input) do begin
      read(ch);
     if ch in ['0'..'9','*'] then begin
      inc(i);
      if can and (ch = '*' ) then begin
        can := false;
        inc(j);
      end;
      if ch in ['0'..'9'] then begin
        o[i] := o[i-1] + ord(ch) - ord('0');
        can := true;
        bh[i] := j;
      end
      else o[i] := 0;
     end;
    end;
   readln;
  end;
  min := maxlongint;
  find := false;
  for i := 1 to n do
  if (bh[i] <> 0) and (bh[i] = bh[i+k-1]) and ((o[i+k-1] - o[i-1]) <
min) then begin
    min := o[i+k-1] - o[i-1];
    find := true;
    rec := i;
  end;
  if find then
  writeln(rec) else writeln(0);
end.