結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2019-08-03 17:44:39 |
言語 | Go (1.23.4) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,182 bytes |
コンパイル時間 | 16,261 ms |
コンパイル使用メモリ | 231,420 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 23:59:54 |
合計ジャッジ時間 | 12,742 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 10 |
ソースコード
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) }