#C4974. Minimum Cities to Visit for Attractions
Minimum Cities to Visit for Attractions
Minimum Cities to Visit for Attractions
You are given n cities, each with a certain number of attractions. Your task is to determine the minimum number of cities you must visit in order to accumulate at least k attractions in total.
More formally, let the attractions in the cities be represented as an array \(a = [a_1, a_2, ..., a_n]\). Find the smallest integer \(m\) (where \(1 \le m \le n\)) such that:
\(\sum_{i=1}^{m} a_{i}^{*} \ge k\)
Here, \(a_{i}^{*}\) represents the attraction counts sorted in non-increasing order. If it is impossible to collect at least k attractions even after visiting all cities, output -1.
inputFormat
The input is given from stdin in the following format:
- The first line contains two integers n and k, where 1 ≤ n ≤ 105 and 1 ≤ k ≤ 109.
- The second line contains n space-separated integers, where the i-th integer represents the number of attractions in the i-th city.
outputFormat
Output a single integer to stdout representing the minimum number of cities you need to visit to accumulate at least k attractions. If it is not possible, output -1.
## sample5 10
4 2 5 3 6
2