use std::io::{self, Read}; #[derive(Debug)] struct Input { l: i32, n: i32, ws: Vec, } fn next_token(cin_lock: &mut io::StdinLock) -> String { cin_lock .by_ref() .bytes() .map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::() } fn read_input(cin_lock: &mut io::StdinLock) -> Input { let l = next_token(cin_lock).parse().unwrap(); let n = next_token(cin_lock).parse().unwrap(); let ws = (0..n) .map(|_| next_token(cin_lock).parse().unwrap()) .collect(); Input { l, n, ws } } fn solve(input: &mut Input, _cin_lock: &mut io::StdinLock) { input.ws.sort(); let ans = input .ws .iter() .scan(0, |sum, &w| { *sum += w; if *sum <= input.l { Some(w) } else { None } }) .count(); println!("{}", ans); } fn main() { let cin = io::stdin(); let mut cin_lock = cin.lock(); let mut input = read_input(&mut cin_lock); solve(&mut input, &mut cin_lock); }