結果

問題 No.617 Nafmo、買い出しに行く
ユーザー tsuchinagatsuchinaga
提出日時 2019-02-28 12:20:05
言語 Go
(1.22.1)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 13,210 ms
コンパイル使用メモリ 217,928 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-09-05 16:05:48
合計ジャッジ時間 17,815 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 36 ms
5,628 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 72 ms
7,972 KB
testcase_06 AC 592 ms
8,312 KB
testcase_07 AC 593 ms
8,308 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 598 ms
8,308 KB
testcase_11 AC 595 ms
8,308 KB
testcase_12 AC 597 ms
8,312 KB
testcase_13 AC 580 ms
8,312 KB
testcase_14 AC 599 ms
8,308 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
	"sort"
	"strconv"
)

func main() {
	var n, k, a int
	_, _ = fmt.Scan(&n, &k)

	nums := make([]int, 0)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&a)
		if a <= k {
			nums = append(nums, a)
		}
	}

	sort.Slice(nums, func(i, j int) bool {
		return nums[i] > nums[j]
	})

	max := 0
	for i := 1; i < int(math.Pow(float64(2), float64(len(nums)))); i++ {
		b := fmt.Sprintf("%0"+strconv.Itoa(len(nums))+"b\n", i)
		sum := 0
		for i, v := range []rune(b) {
			if string(v) == "1" {
				sum += nums[i]
				if sum > k {
					break
				}
			}
		}
		if sum <= k && max < sum {
			max = sum
		}
	}

	fmt.Println(max)
}
0