记录编号 21483 评测结果 AAAAAAAAWA
题目名称 [POJ 2823]滑动窗口 最终得分 90
用户昵称 Gravatargragon 是否通过 未通过
代码语言 Pascal 运行时间 2.773 s
提交时间 2010-11-11 07:54:35 内存使用 10.40 MiB
显示代码纯文本
program ex;
var
a:array[1..1000000] of longint;
f:array[1..1000000,1..2] of longint;
min,max,i,j,n,k,z,r:longint;

procedure init;
begin
  assign(input,'window.in');
  assign(output,'window.out');
  reset(input);
  rewrite(output);
  readln(n,k);
  for i:=1 to n do read(a[i]);
  close(input);
end;

begin
  init;
  min:=maxlongint;
  max:=0;
  for i:=1 to k do
  begin
    if a[i]<min then min:=a[i];
    if a[i]>max then max:=a[i];
  end;
  f[1,1]:=min;
  f[1,2]:=max;
  i:=1;j:=k;z:=1;
  while (j<n) do
  begin
    inc(i);inc(j);inc(z);
    if (a[i-1]<>max)and(a[i-1]<>min) then
    begin
      if a[j]>max then max:=a[j];
      if a[j]<min then min:=a[j];
    end
    else
    begin
      if (a[i-1]=max) then
      begin
        if (a[j]<min) then min:=a[j];
        if (a[j]<max) then
        begin
          max:=0;
          for r:=i to j do
          if (a[r]>max) then max:=a[r];
        end
        else
        max:=a[j];
      end;
      if (a[i-1]=min) then
      begin
        if (a[j]>max) then max:=a[j];
        if (a[j]>min) then
        begin
          min:=maxlongint;
          for r:=i to j do
          if (a[r]<min) then min:=a[r];
        end
        else
        min:=a[j];
      end;
    end;
    f[z,1]:=min;
    f[z,2]:=max;
  end;
  for i:=1 to n-k do write(f[i,1],' ');
  writeln(f[n-k+1,1]);
  for i:=1 to n-k do write(f[i,2],' ');
  writeln(f[n-k+1,2]);
  close(output);
end.