結果
| 問題 | No.5 数字のブロック |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-03 18:03:56 |
| 言語 | Go (1.26.1) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 969 bytes |
| 記録 | |
| コンパイル時間 | 10,936 ms |
| コンパイル使用メモリ | 281,356 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2026-03-27 11:52:28 |
| 合計ジャッジ時間 | 11,987 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
package main
import (
"bufio"
"fmt"
"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
index := 0
for i, v := range ary {
sum += v
if boxWidth < sum {
index = i
break
}
}
if index == 0 {
fmt.Println(len(ary))
} else {
fmt.Println(index)
}
}
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 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)
}