Created
December 11, 2016 09:55
-
-
Save Kanol/5d80eb22a70342f4cbc8c68732a3c96e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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