VCOWCAR - Xe ô tô của bò

Tác giả: RR

Ngôn ngữ: Pascal

{$R-,Q-}
//super fast algorithm invented by mr_invincible
const
  FINP='';
  FOUT='';
  MAXN=50000;
var
  n,l,m,d,kq:longint;
  a:array[1..MAXN] of longint;
procedure inp; inline;
var
  f:text;
  i:longint;
begin
  assign(f,FINP); reset(f);
  read(f,n,m,d,l);
  for i:=1 to n do read(f,a[i]);
  close(f);
end;
procedure swap(var a,b:longint); inline;
var
  temp:longint;
begin
  temp:=a; a:=b; b:=temp;
end;
procedure sort(l,r:longint); inline;
var
  i,j,mid:longint;
begin
  i:=l; j:=r; mid:=a[l+random(r-l+1)];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then
      begin
        swap(a[i],a[j]);
        inc(i); dec(j);
      end;
  until i>j;
  if i<r then sort(i,r);
  if l<j then sort(l,j);
end;
procedure ans; inline;
var
  f:text;
  i:longint;
begin
  assign(f,FOUT); rewrite(f);
  kq:=0;
  for i:=1 to n do
    if a[i]-d*(kq div m)>=l then inc(kq);
  writeln(f,kq);
  close(f);
end;
begin
  inp;
  sort(1,n);
  ans;
end.

Download