Problem:
Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.

Solution in Rust (1.42.0) (judge verdict: Accepted)

use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}

#[allow(unused_imports)]
use std::io::{stdout, Write};
#[allow(unused_imports)]
use std::collections::HashMap;
fn gcd(mut x: u64, mut y: u64) -> u64 {
    let mut z = x;
    let mut gcd_num = x;
    while z != 0 {
        gcd_num = z;
        z = y % x;
        y = x;
        x = z;
    }
    gcd_num
}
#[allow(dead_code)]
fn tansaku_fn(iti: usize, n: usize, kyori: &mut Vec<i32>, map: &Vec<Vec<bool>>, ans: &mut Vec<usize>) {
    let mut tansaku1: Vec<usize> = Vec::new();
    for j in 0..n {
        if map[iti][j] == true {
            tansaku1.push(j);
        }
    }
    let mut tansaku2: Vec<usize> = Vec::new();
    for j in tansaku1 {
        if kyori[j] > kyori[iti] + 1 {
            kyori[j] = kyori[iti] + 1;
            ans[j] = iti;
            tansaku2.push(j);
        }
    }
    for iti1 in tansaku2{
        tansaku_fn(iti1, n, kyori, map, ans);
    }
}

fn is_prime(i: i64) -> bool {
    for j in 2..i/2 {
        if i % j == 0 {
            return false
        }
    }
    return true
}
fn main() {
    let (n, x) = read_two::<i64>();
    let mut v: Vec<i64> = read_vec();
    v.sort();
    let sum: i64 = v.iter().fold(0, |sum, a| sum + a);
    if sum < x {
        println!("{}", n - 1);
        return
    }
    let mut temp = 0;
    for i in 0..n {
        let j = v[i as usize];
        if temp + j == x {
            println!("{}", i + 1);
            return
        }
        if temp + j > x {
            println!("{}", i);
            return
        }
        temp += j;
    }
    println!("{}", n);
}