結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2019-08-03 18:03:56 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 969 bytes |
| コンパイル時間 | 10,301 ms |
| コンパイル使用メモリ | 242,480 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 01:37:49 |
| 合計ジャッジ時間 | 11,247 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)
}