結果

問題 No.115 遠足のおやつ
ユーザー te-sh
提出日時 2017-01-30 13:54:13
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 103,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 06:42:15
合計ジャッジ時間 1,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], d = rd[1], k = rd[2];

  auto comSum(int i, int j) {
    return i > j ? 0 : (j * (j + 1) - (i - 1) * i) / 2;
  }

  auto calc(int a, int b) {
    return comSum(1, a) + comSum(b, n);
  }

  auto a = k, b = n + 1, c = -1;
  if (comSum(1, k) > d || comSum(n - k + 1, n) < d) {
    writeln(-1);
  } else {
    while (calc(a, b) < d) {
      if (calc(a - 1, b - 1) < d) {
        --a;
        --b;
      } else {
        c = a + d - calc(a, b);
        --a;
        break;
      }
    }

    auto r = iota(1, a+1).array ~ (c > 0 ? [c] : []) ~ iota(b, n+1).array;
    writeln(r.to!(string[]).join(" "));
  }
}
0