結果

問題 No.115 遠足のおやつ
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-15 16:54:09
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 937 bytes
コンパイル時間 14,000 ms
コンパイル使用メモリ 203,000 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-31 00:52:09
合計ジャッジ時間 15,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 0 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,384 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"strings"
)

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

	// k個を満たす最低と最大の金額を出す
	total := 0
	nums := make([]int, k)
	for i := 1; i <= k; i++ {
		total += i
		nums[i-1] = i
	}
	// fmt.Println(total)
	// fmt.Println(nums)

	// 後ろからなるべく合計に近づくように調整していく
	t := k - 1
	for i := n; i > 0; i-- {
		if nums[t] == i { // 変えたいところと変えられるものが一致した時点で詰み
			break
		}

		u := total - nums[t] + i
		if u == d {
			total = u
			nums[t] = i
			t--
		} else if u < d {
			total = u
			nums[t] = i
			t--
		}

		if t < 0 { // tが小さくなりすぎてもNG
			break
		}
	}
	// fmt.Println(total, d)
	// fmt.Println(nums)

	if total == d {
		s := ""
		for _, n := range nums {
			s = fmt.Sprintf("%s %d", s, n)
		}
		fmt.Println(strings.Trim(s, " "))
	} else {
		fmt.Println(-1)
	}
}
0