Pagini recente » Cod sursa (job #1032261) | Cod sursa (job #2076279) | jc2020-runda2 | Diferente pentru implica-te/arhiva-educationala intre reviziile 221 si 220 | Cod sursa (job #713279)
Cod sursa(job #713279)
var
procedure qsort(var v :vect);
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=v[(l+r) div 2];
repeat
while (v[i].c<x.c)or((v[i].c=x.c)and(v[i].g<x.g)) do
inc(i);
while (v[i].c>x.c)or((v[i].c=x.c)and(v[i].g>x.g)) do
dec(j);
if not(i>j) then
begin
y:=v[i];
v[i]:=v[j];
v[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
sort(1,max);
end;
begin
assign(input,'rucsac.in');reset(input);
rewrite(output,'rucsac.out');rewrite(output);
read(n,g2);
for i:=1 to n do
read(v[i].g,v[i].c);
qsort(v);
max:=n;
s:=0;
for i:=1 to n do
if (gr+v[i].g<=g2) then