#K72882. Minimum Repositories for Stars

    ID: 33852 Type: Default 1000ms 256MiB

Minimum Repositories for Stars

Minimum Repositories for Stars

You are given a list of repositories with their respective star counts. Your task is to determine the minimum number of repositories required so that the total stars reach or exceed a given target value.

Formally, given an integer \(n\) and a list of integers \(a_1, a_2, \dots, a_n\) representing the stars of each repository, and an integer \(T\) representing the target star count, you need to find the smallest integer \(k\) (with \(1 \le k \le n\)) such that the sum of the \(k\) largest star counts is at least \(T\). If it is impossible to reach \(T\), output \(-1\).

The problem can be mathematically formulated as finding the smallest \(k\) satisfying:

\[ \sum_{i=1}^{k} a_{(i)} \ge T, \]

where \(a_{(1)} \ge a_{(2)} \ge \cdots \ge a_{(n)}\) is the list of stars sorted in decreasing order.

inputFormat

The input is read from stdin and consists of three lines:

  • The first line contains an integer \(n\) representing the number of repositories.
  • The second line contains \(n\) space-separated integers representing the star counts of each repository.
  • The third line contains an integer \(T\) representing the target star count.

outputFormat

Output to stdout a single integer representing the minimum number of repositories needed to reach or exceed the target star count. If it is not possible, output \(-1\).

## sample
5
1 2 3 4 5
11
3