记录编号 101647 评测结果 AAAAAAAAAA
题目名称 [USACO Nov07] 挤奶时间 最终得分 100
用户昵称 GravatarMID_VAMPIRE 是否通过 通过
代码语言 Pascal 运行时间 0.008 s
提交时间 2014-05-13 17:48:01 内存使用 0.20 MiB
显示代码纯文本
var l,r,z,f,g:array[0..2000]of longint;
    n,t,m,i,w:longint;
procedure swap(var x,y:longint);
var t:longint;
begin
  {x:=x xor y;
  y:=x xor y;
  x:=x xor y;}
  t:=x; x:=y; y:=t;
end;
procedure sort(p,q:longint);
var i,j,x,y,k:longint;
begin
  k:=(p+q)>>1;//random(q-p)+p;
  i:=p; j:=q; y:=l[k]; x:=r[k];
  repeat
    while (x>r[i])or((x=r[i])and(y>l[i])) do inc(i);
    while (x<r[j])or((x=r[j])and(y<l[j])) do dec(j);
    if i<=j then
      begin
        swap(l[i],l[j]);
        swap(r[i],r[j]);
        swap(z[i],z[j]);
        inc(i); dec(j);
      end;
  until i>j;
  if i<q then sort(i,q);
  if j>p then sort(p,j);
end;
function max(x,y:longint):longint;
begin
  if x<y then exit(y);
  exit(x);
end;
begin
  assign(input,'milkprod.in');reset(input);assign(output,'milkprod.out');rewrite(output);
  readln(n,m,w);
  fillchar(l,sizeof(l),0);
  fillchar(r,sizeof(r),0);
  fillchar(z,sizeof(z),0);
  for i:=1 to m do readln(l[i],r[i],z[i]);
  sort(1,m);
  fillchar(g,sizeof(g),0);
  fillchar(f,sizeof(f),0);
  for i:=1 to m do
    begin
      t:=i-1;
      while (t>0)and(r[t]+w>l[i]) do dec(t);
      f[i]:=g[t]+z[i];
      g[i]:=max(f[i],g[i-1]);
    end;
  writeln(g[m]);
  close(input);close(output);
end.