結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
|
提出日時 | 2016-08-31 10:41:42 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 658 ms |
コンパイル使用メモリ | 118,596 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 03:59:00 |
合計ジャッジ時間 | 1,704 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
import std.algorithm, std.array, std.container, std.range; import std.string, std.conv; import std.math, std.bigint, std.bitmanip, std.random; import std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto n = rd[0], d = rd[1], k = rd[2]; if (d < comSum(k) || d > comSum(k) + (n - k) * k) { writeln(-1); } else { auto ai = iota(k).map!(to!int).map!("a + 1").array; foreach_reverse (i; 0..k) { if (ai.sum >= d) break; if (ai.sum < d) { auto b = n - k + 1 + i; auto c = d - (comSum(i) + comSum(k - i - 2) + (b + 1) * (k - i - 1)); ai[i] = min(b, c); } } writeln(ai.map!(to!string).join(' ')); } } int comSum(int k) { return k * (k + 1) / 2; }