結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー Iván Soto
提出日時 2022-08-05 22:36:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 194,920 KB
最終ジャッジ日時 2025-01-30 18:27:14
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long s;
  cin >> n >> s;
  vector<int> ans;
  while (s > n) {
    ans.push_back(n);
    s -= n;
    --n;
  }
  ans.push_back(s);
  reverse(ans.begin(), ans.end());
  cout << ans.size() << '\n';
  for (const auto& e : ans) {
    cout << e << ' ';
  }
  cout << '\n';
  return 0;
}
0