Pagini recente » Cod sursa (job #108057) | Cod sursa (job #803080) | Cod sursa (job #933525) | Cod sursa (job #1177580) | Cod sursa (job #163621)
Cod sursa(job #163621)
program peste;
type fishp=record
p,t:word;
end;
var f:text;
k,n,tt,i,maxp,nt,j,nr,e:longint;
v,vp:array[1..50000] of fishp;
t:array[1..1000] of word;
c:array[1..1000] of longint;
l:array[1..50000] of longint;
ctrl:boolean;
procedure qsort(bal,jobb:word);
var i,j,va:word;
cs:fishp;
begin
i:=bal;j:=jobb;
va:=v[(i+j) div 2].t;
while(i<=j) do
begin
while(v[i].t < va) do inc(i);
while(v[j].t > va) do dec(j);
if(i<=j) then
begin
cs:=v[i];
v[i]:=v[j];
v[j]:=cs;
inc(i);dec(j);
end;
end;
if(bal < j) then qsort(bal,j);
if(i < jobb) then qsort(i,jobb);
end;
procedure qsortp(bal,jobb:word);
var i,j,va:word;
cs:fishp;
begin
i:=bal;j:=jobb;
va:=vp[(i+j) div 2].p;
while(i<=j) do
begin
while(vp[i].p > va) do inc(i);
while(vp[j].p < va) do dec(j);
if(i<=j) then
begin
cs:=vp[i];
vp[i]:=vp[j];
vp[j]:=cs;
inc(i);dec(j);
end;
end;
if(bal < j) then qsortp(bal,j);
if(i < jobb) then qsortp(i,jobb);
end;
begin
assign(f,'peste.in');
reset(f);
readln(f,n,k,tt);
for i:=1 to n do
readln(f,v[i].p,v[i].t);
close(f);
vp:=v;
qsort(1,n);
qsortp(1,n);
i:=1;
while(i<=n) do
begin
maxp:=i;
while (i<n) and (v[i].t = v[i+1].t) do
begin
inc(i);
if(v[i].p > v[maxp].p) then maxp:=i;
end;
inc(nt);
t[nt]:=maxp;
inc(i);
end;
for i:=1 to nt do
begin
j:=1;
nr:=1;
c[i]:=v[t[i]].p;
ctrl:=false;
while (nr<k) and (j<=n) do
begin
if (vp[j].t <= v[t[i]].t) and
((v[t[i]].p <> vp[j].p) or ((v[t[i]].t) <> (vp[j].t)) or (ctrl)) then
begin
inc(nr);
c[i]:=c[i]+vp[j].p;
end;
if(v[t[i]].p = vp[j].p) and (v[t[i]].t = vp[j].t) then ctrl:=true;
inc(j);
end;
end;
for i:=1 to nt do
if(v[t[i]].t <= tt) then
begin
if(c[i] > l[v[t[i]].t]) then l[v[t[i]].t]:=c[i];
if(l[v[t[i]].t] > e) then e:=l[v[t[i]].t];
end;
for i:=1 to tt do
begin
if(l[i] > 0) then
begin
for j:=1 to nt do
if(i+v[t[j]].t <= tt) then
begin
if(c[j]+l[i] > l[i+v[t[j]].t]) then l[i+v[t[j]].t]:=l[i]+c[j];
if(l[i+v[t[j]].t] > e) then e:=l[i+v[t[j]].t];
end;
end;
end;
assign(f,'peste.out');
rewrite(f);
writeln(f,e);
close(f);
end.