1 / 3
Dec 2019

An have N mp3 music files, have the size of A1,A2,…AN.
An want to write some file on to a cd have a storage capacity of s.
Help An pick as many music file as possible to write on the cd

  • created

    Dec '19
  • last reply

    Dec '19
  • 2

    replies

  • 721

    views

  • 2

    users

This sounds like it might be homework.

Think about it… how would you go about it?

Figured out how to do this
var a:array[1…100] of longint;
n,i,s,d,j,t,f:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
d:=0;
f:=0;
For i:=1 To N-1 Do
For j:=i+1 To N Do
If A[i]>A[j] Then
Begin
T:=A[i]; A[i]:=A[j]; A[j]:=T;
End;

for i:=1 to n do
begin
if f+a[i]>s then break;
f:=f+a[i];
d:=d+1;
end;
writeln(d);
end.