結果

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

ソースコード

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 (calc(a, b) > d || calc(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 ~ iota(b, n+1).array;
    writeln(r.to!(string[]).join(" "));
  }
}
0