結果

問題 No.115 遠足のおやつ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-02-27 10:43:21
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 379 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 11,556 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-08-31 00:56:56
合計ジャッジ時間 5,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,296 KB
testcase_01 AC 81 ms
15,352 KB
testcase_02 AC 81 ms
15,124 KB
testcase_03 AC 79 ms
15,264 KB
testcase_04 AC 81 ms
15,128 KB
testcase_05 AC 80 ms
15,340 KB
testcase_06 AC 80 ms
15,180 KB
testcase_07 AC 81 ms
15,164 KB
testcase_08 AC 80 ms
15,172 KB
testcase_09 AC 80 ms
15,180 KB
testcase_10 AC 82 ms
15,128 KB
testcase_11 AC 80 ms
15,068 KB
testcase_12 AC 81 ms
15,332 KB
testcase_13 AC 80 ms
15,172 KB
testcase_14 AC 79 ms
15,356 KB
testcase_15 AC 79 ms
15,156 KB
testcase_16 AC 80 ms
15,316 KB
testcase_17 AC 80 ms
15,136 KB
testcase_18 AC 81 ms
15,044 KB
testcase_19 AC 80 ms
15,348 KB
testcase_20 AC 79 ms
15,280 KB
testcase_21 AC 79 ms
15,168 KB
testcase_22 AC 79 ms
15,032 KB
testcase_23 AC 79 ms
15,140 KB
testcase_24 AC 80 ms
15,136 KB
testcase_25 AC 80 ms
15,344 KB
testcase_26 AC 82 ms
15,176 KB
testcase_27 AC 81 ms
15,256 KB
testcase_28 AC 81 ms
15,152 KB
testcase_29 AC 81 ms
15,148 KB
testcase_30 AC 80 ms
15,292 KB
testcase_31 AC 81 ms
15,352 KB
testcase_32 AC 80 ms
15,284 KB
testcase_33 AC 80 ms
15,348 KB
testcase_34 AC 79 ms
15,148 KB
testcase_35 AC 80 ms
15,284 KB
testcase_36 AC 80 ms
15,304 KB
testcase_37 AC 80 ms
15,348 KB
testcase_38 AC 82 ms
15,136 KB
testcase_39 AC 80 ms
15,284 KB
testcase_40 AC 80 ms
15,152 KB
testcase_41 AC 78 ms
15,076 KB
testcase_42 AC 78 ms
15,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

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
0