Cod sursa(job #277356)

Utilizator PatrunjeluMarginean Bogdan Alexandru Patrunjelu Data 11 martie 2009 17:43:58
Problema Text Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.06 kb
var gmax,nrob,i,max,secg,deret,check,j,m,n:integer;
    greutatiob:array[1..900,1..900] of integer;
    ok:boolean;
begin
//WOOOOO!
write('Greutatea maxima de dus a slabanogului este:');
readln(gmax);
secg:=gmax;
write('Numarul obiectelor care alcatuiesc crucea slabanogului este:');
readln(nrob);
for i:=1 to nrob do begin
write('Obiectul cu numarul ', i,' cantareste:'); readln(greutatiob[i,1]);
write('Obiectul cu numarul ', i,' aduce profit egal cu:'); readln(greutatiob[i,2]);
end;
max:=0;
i:=0;
Write('El va cara, pentru profit maxim, obiectele: ');
repeat
check:=0;
max:=0;
  for i:=1 to nrob do begin
     if (greutatiob[i,2] > max) and (greutatiob[i,1] <= secg) then begin
     max:=greutatiob[i,2];
     deret:=i;
     end;
  end;
  if greutatiob[deret,1] <= secg then begin
  greutatiob[deret,2]:=0;
  secg:=secg - greutatiob[deret,1];
  greutatiob[deret,1]:=gmax;
  end;
  write(deret,' ');
   for i:=1 to nrob do begin
     if greutatiob[i,1] > secg then begin
     check:=check + 1;
     end;
   end;
until check = nrob;
readln;
end.