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 mut ans = 0; let mut sum = 0; for w in input.ws.iter() { if sum + w > input.l { break; } sum += w; ans += 1; } 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); }