package main import ( "bufio" "fmt" "io" "os" "sort" "strconv" "strings" ) var reader = bufio.NewReaderSize(os.Stdin, 1000000) func main() { boxWidth := newInt() boxNumber := newInt() line := readLine() strs := strings.Split(line, " ") ary := make([]int, boxNumber) for i := range strs { ary[i], _ = strconv.Atoi(strs[i]) } sort.Sort(sort.IntSlice(ary)) sum := 0 for i, v := range ary { sum += v if boxWidth < sum { fmt.Println(i) break } } } func readLine() string { buf := make([]byte, 0, 1000000) for { l, p, e := reader.ReadLine() if e != nil { panic(e) } buf = append(buf, l...) if !p { break } } return string(buf) } func readInt() int { line, e := reader.ReadString(' ') if e != nil { if e == io.EOF { i, _ := strconv.ParseInt(line, 10, 0) return int(i) } panic(e) } line = strings.TrimRight(line, " ") i, e := strconv.ParseInt(line, 10, 0) if e != nil { panic(e) } return int(i) } func newInt() int { line, e := reader.ReadString('\n') if e != nil { panic(e) } line = strings.TrimRight(line, "\r\n") i, e := strconv.ParseInt(line, 10, 0) if e != nil { panic(e) } return int(i) }