ac1075b.pas

来自「同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料」· PAS 代码 · 共 38 行

PAS
38
字号
program tju1075;
const
  maxn=300000;
  modulo=128;
var
  shigh,phigh:array[0..maxn]of integer;
  slow,plow:array[0..maxn]of shortint;
  t,u,n,l1,l2,i,x,s,f,r,ans,tmp:longint;
procedure save(var a:integer;var b:shortint;c:longint);
  begin
    a:=c div modulo;b:=c mod modulo;
  end;
function sum(x:longint):longint;
  begin
    sum:=shigh[x]*modulo+slow[x];
  end;
function pos(x:longint):longint;
  begin
    pos:=phigh[x]*modulo+plow[x];
  end;
begin
  read(t);
  for u:=1 to t do begin
    read(n,l1,l2);ans:=-maxlongint;s:=0;f:=1;r:=0;
    for i:=1 to n do begin
      read(x);inc(s,x);save(shigh[i],slow[i],s);
      if i<l1 then continue;
      while (f<=r) and (i-pos(f)>l2) do inc(f);
      tmp:=sum(i-l1);
      while (f<=r) and (tmp<=sum(pos(r))) do dec(r);
      inc(r);save(phigh[r],plow[r],i-l1);
      tmp:=s-sum(pos(f));
      if tmp>ans then ans:=tmp;
    end;
    writeln(ans);
  end;
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?