結果

問題 No.5 数字のブロック
ユーザー cm-arai
提出日時 2021-01-02 16:11:14
言語 Go
(1.23.4)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 515 bytes
コンパイル時間 12,585 ms
コンパイル使用メモリ 228,804 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2024-10-12 05:01:45
合計ジャッジ時間 11,288 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func scan() (L int, N int, W []int) {
	fmt.Scan(&L)
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var w int
		fmt.Scan(&w)
		W = append(W, w)
	}
	return L, N, W
}

func main() {
	L, _, W := scan()
	// L, _, W := 1, 1, []int{1}
	// L, _, W := 16, 3, []int{10, 5, 7}
	// L, _, W := 100, 10, []int{14, 85, 77, 26, 50, 45, 66, 79, 10, 3}
	sort.IntSlice(W).Sort()

	count := 0
	sum := 0

	for _, w := range W {
		sum += w
		if sum > L {
			break
		}
		count++
	}
	fmt.Print(count)
}
0