結果

問題 No.115 遠足のおやつ
ユーザー ninoinui
提出日時 2020-11-21 19:53:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 888 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 196,024 KB
最終ジャッジ日時 2025-01-16 04:09:59
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 1 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N, D, K;
  cin >> N >> D >> K;

  vector<int> ans(K);
  iota(ans.begin(), ans.end(), 1);

  if (ans.back() > N) return cout << -1 << "\n", 0;
  if (accumulate(ans.begin(), ans.end(), 0) > D) return cout << -1 << "\n", 0;

  int tmp = D - accumulate(ans.begin(), ans.end(), 0);

  int now = K - 1, mx = N;
  while (tmp) {
    ans.at(now)++, tmp--;
    if (ans.at(now) == mx) now--, mx--;
  }

  if (accumulate(ans.begin(), ans.end(), 0) > D) return cout << -1 << "\n", 0;
  
  for (int i = 0, n = ans.size(); i < n; i++) {
    cout << ans.at(i) << ((i == n - 1) ? "\n" : " ");
  }
}
0