printРабочее место участника

printЗадачи

2334. Elephants

Ограничения: время – 200ms/500ms, память – 256MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

36396.jpg
On the screen Moriarty began to sing nursery rhyme.
One elephant went out to play
Upon a Spiders web one day
He had such enormous fun
That he called for another elephant to come.
Two elephants went out to play
Upon a Spiders web one day
They had such enormous fun
That they called for another elephant to come…
Sherlock thought. "Suppose we have a set of `M` elephants, each one with a weight `w_i`, and we know the maximum weight that the spider's web supports, what is the largest number of elephants that we can put in the spider web without breaking it?"
Input
The first line of input contains two integers `M` and `W`, the number of elephants and the maximum weight that the spider web supports (`1\ ≤\ M\ ≤\ 1000` and `1\ ≤\ W\ ≤\ 10^8`). The next line contains `M` numbers `w_i` representing the weight of each elephant (`1\ ≤\ w_i\ ≤\ 10^5`).
Output
Print a single line with the largest number of elephants that we can put in the spider's web without breaking it.

Sample Input 1

5 14
11 16 3 17 18

Sample Output 1

2

Sample Input 2

4 15
1 2 3 4

Sample Output 2

4
loading