結果

問題 No.115 遠足のおやつ
ユーザー siman
提出日時 2015-01-13 02:47:46
言語 Ruby
(3.4.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 548 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-06-22 04:36:47
合計ジャッジ時間 4,410 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 RE * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class A
  def initialize
    n, d, k = gets.chomp.split(' ').map(&:to_i)

    answer = [*(1..k-1)] + [d-(1..k-1).inject(:+)]

    diff = answer.last - n

    if diff > 0
      answer[-1] -= diff

      (k-2).downto(0) do |index|
        sub = [diff, (answer[index+1] - 1) - answer[index]].min
        answer[index] += sub
        diff -= sub

        break if diff.zero?
      end
    end

    if answer.inject(:+) == d and answer.uniq.size == k and answer.all?{|i| i > 0}
      puts answer.join(' ')
    else
      puts -1
    end
  end
end

A.new
0