Skip to content

Instantly share code, notes, and snippets.

@Kanol
Created December 11, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kanol/5d80eb22a70342f4cbc8c68732a3c96e to your computer and use it in GitHub Desktop.
Save Kanol/5d80eb22a70342f4cbc8c68732a3c96e to your computer and use it in GitHub Desktop.
program balloons;
var amount, maxWeigth, i, minimum, currentWeigth, maximum, outputAmount, minimumIndex:integer;
weigth: array of integer;
isMax:boolean;
begin
readln(amount, maxWeigth);
setlength(weigth, maxWeigth);
maximum:=0;
for i := 1 to amount do begin
read(weigth[i]);
if weigth[i]>maximum then
maximum:=weigth[i];
end;
isMax:=false;
while (not isMax) do begin
minimum:=maximum;
for i := 1 to amount do begin
if (weigth[i]<minimum) and (weigth[i]<>0) then begin
minimum:=weigth[i];
minimumIndex:=i;
end;
end;
weigth[minimumIndex]:=0;
if currentWeigth+minimum<=maxWeigth then begin
currentWeigth:=currentWeigth+minimum;
outputAmount:=outputAmount+1;
end
else
isMax:=true;
end;
writeln(outputAmount);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment