結果

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

ソースコード

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) {
    while (ans.at(now) == mx) {
      now--, mx--;
      if (now < 0) return cout << -1 << "\n", 0;
    }
    ans.at(now)++, tmp--;
  }

  if (ans.back() > N) return cout << -1 << "\n", 0;
  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