macro_rules! scan_iter { ($buf:expr) => {{ use std::io::{stdin, BufRead}; use std::str::FromStr; $buf.clear(); stdin().lock().read_line(&mut $buf).unwrap(); $buf.trim() .split(" ") .map(|x| FromStr::from_str(x).unwrap()) }}; } macro_rules! scan_vec { ($buf:expr) => { scan_iter!($buf).collect::>() }; } macro_rules! scan { ($buf:expr) => {{ use std::io::{stdin, BufRead}; use std::str::FromStr; $buf.clear(); stdin().lock().read_line(&mut $buf).unwrap(); FromStr::from_str($buf.trim()).unwrap() }}; } macro_rules! ignore { () => {{ use std::io::{stdin, BufRead}; stdin().lock().read_line(&mut String::new()).unwrap(); }}; } fn main() { let mut b = String::new(); let l: i32 = scan!(b); ignore!(); let w: Vec = { let mut w = scan_vec!(b); w.sort_unstable(); w }; let mut cap = l; let mut count = 0; for b in w { if cap < b { break; } cap -= b; count += 1; } println!("{count}"); }