結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2019-04-15 16:53:10 |
言語 | Go (1.23.4) |
結果 |
RE
|
実行時間 | - |
コード長 | 873 bytes |
コンパイル時間 | 11,082 ms |
コンパイル使用メモリ | 220,760 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 07:59:37 |
合計ジャッジ時間 | 12,380 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 RE * 11 |
ソースコード
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) } }