結果

問題 No.5 数字のブロック
ユーザー k.h
提出日時 2019-08-03 18:02:54
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 937 bytes
コンパイル時間 13,297 ms
コンパイル使用メモリ 224,676 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 01:29:47
合計ジャッジ時間 14,379 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
	}
}

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)
}
0