結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2020-02-27 10:43:21 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 101 ms / 5,000 ms |
コード長 | 379 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 8,192 KB |
実行使用メモリ | 13,056 KB |
最終ジャッジ日時 | 2025-01-03 01:53:00 |
合計ジャッジ時間 | 5,284 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
Main.rb:5: warning: ambiguous first argument; put parentheses or a space even after `-` operator Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-` operator Syntax OK
ソースコード
def min(a,b); a < b ? a : b; end N, D, K = gets.split.map(&:to_i) if K > N puts -1 exit end ANS = Array.new(K){|i| K - i } rest = K.times.inject(D) do |d, i| r = K - i sum = r * (r + 1) / 2 if sum > d ANS.clear ANS << -1 break 1 else ANS[i] += min(d - sum, N - K) d - ANS[i] end end if rest > 0 puts -1 else puts ANS.reverse.join(' ') end