Cod sursa(job #713279)

Utilizator alex45meOlaru Alex alex45me Data 14 martie 2012 14:51:07
Problema Problema rucsacului Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.95 kb
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