#C2559. Maximum Number of Photos
Maximum Number of Photos
Maximum Number of Photos
You are provided with a list of photo file sizes (in bytes) and a storage capacity (in bytes). Your task is to determine the maximum number of photos that can be stored without exceeding the storage capacity.
To maximize the count, you should start storing the smallest photos first. More formally, given a sequence of photo sizes \(a_1, a_2, \dots, a_n\) (after sorting in non-decreasing order), determine the maximal \(k\) such that:
\(\sum_{i=1}^{k} a_i \leq C\),
where \(C\) is the given capacity.
inputFormat
The first line contains two integers (n) and (C), where (n) is the number of photos and (C) is the storage capacity in bytes. The second line contains (n) space-separated integers representing the sizes of the photos.
outputFormat
Output a single integer representing the maximum number of photos that can be stored without exceeding the given capacity.## sample
4 800000000
200000000 150000000 300000000 500000000
3