Pagini recente » Cod sursa (job #2973712) | Cod sursa (job #2092260) | Cod sursa (job #931918) | Cod sursa (job #2759535) | Cod sursa (job #19290)
Cod sursa(job #19290)
const maxn=75000;maxbuc=200;oo=maxlongint div 4;
var t:text;
count:array[0..maxbuc]of longint;
modu,invu,tmp,lo,hi,i,n,g,cit,rest:longint;
Q,V,Scade:Array[0..maxn]of longint;
Best:array[0..1,0..maxn]of longint;
Procedure dinamica(tip,dist:longint;var A,B:array of longint);
var i,j:longint;
begin
hi:=0;
for i:=G downto 0 do
begin scade[i]:=hi;V[i]:=A[i]+hi;if i mod tip=0 then inc(hi);end;
for rest:=0 to tip-1 do
begin
lo:=1;hi:=0;i:=rest;
while i<=G do
begin
if i>=tip*dist then j:=dist else j:=i div tip;
while (lo<=hi)and(V[Q[hi]]>v[i]) do dec(hi);inc(hi);Q[hi]:=i;
while Scade[Q[lo]]>Scade[i]+j do inc(lo);
tmp:=V[Q[lo]]-Scade[i];if tmp<A[i] then B[i]:=tmp else B[i]:=A[i];
inc(i,tip);
end;
end;
end;
begin
assign(t,'ghiozdan.in');reset(T);readln(t,n,G);
for i:=1 to N do begin readln(t,cit);inc(count[cit]);end;close(T);
for i:=1 to G do Best[0,i]:=oo;
for i:=1 to maxbuc do
begin
modu:=i and 1;invu:=1-modu;
Dinamica(i,count[i],best[invu],Best[modu]);
end;
for i:=G downto 0 do if Best[modu,i]<>oo then break;
assign(t,'ghiozdan.out');rewrite(T);writeln(t,i,' ',Best[modu,i]);
close(t);
end.