#C4713. Maximizing Server Request Handling

    ID: 48282 Type: Default 1000ms 256MiB

Maximizing Server Request Handling

Maximizing Server Request Handling

You are given a list of request sizes and a server capacity. Your task is to determine the maximum number of requests that can be processed without exceeding the given capacity. To solve this problem, you can use a greedy algorithm. First, sort the request sizes in non-decreasing order, then select requests one by one until adding the next request would exceed the capacity. Formally, if the sorted list is (a_1, a_2, \ldots, a_n), you need to find the maximum integer (k) such that (\sum_{i=1}^{k} a_i \leq capacity).

inputFormat

The input consists of two lines:

  1. The first line contains space-separated integers representing the sizes of the requests. (It can be empty if there are no requests.)
  2. The second line contains a single integer representing the server's capacity.

outputFormat

Output a single integer on a new line representing the maximum number of requests that can be handled without exceeding the capacity.## sample

4 8 5 9
20
3