#K66722. Maximum Landmarks Visited Within Budget

    ID: 32484 Type: Default 1000ms 256MiB

Maximum Landmarks Visited Within Budget

Maximum Landmarks Visited Within Budget

You are given a set of landmarks, each with an associated price, and a fixed budget. Your task is to determine the maximum number of unique landmarks that can be visited without exceeding the budget. To maximize the number of visits, you should choose the cheapest landmarks first. Formally, given a sorted list of prices (p_1 \le p_2 \le \cdots \le p_n) and a budget (B), find the largest integer (k) such that (\sum_{i=1}^{k} p_i \le B).

inputFormat

The input consists of three lines:

  1. The first line contains an integer (n) (1 ≤ (n) ≤ 10^5), representing the number of landmarks.
  2. The second line contains (n) space-separated integers which denote the prices of the landmarks.
  3. The third line contains an integer (B) (0 ≤ (B) ≤ 10^9), representing the available budget.

outputFormat

Output a single integer indicating the maximum number of landmarks you can visit without exceeding the budget.## sample

5
20 10 30 50 40
70
3

</p>