結果

問題 No.115 遠足のおやつ
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-15 16:53:10
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 873 bytes
コンパイル時間 14,657 ms
コンパイル使用メモリ 214,284 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:43:38
合計ジャッジ時間 13,755 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 RE -
testcase_22 AC 1 ms
4,348 KB
testcase_23 RE -
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 RE -
testcase_37 AC 1 ms
4,348 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 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--
		}
	}
	// 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