結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー polyester
提出日時 2022-08-05 22:19:41
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 4,200 ms
コンパイル使用メモリ 144,260 KB
実行使用メモリ 5,456 KB
最終ジャッジ日時 2024-09-15 19:24:36
合計ジャッジ時間 6,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll s, n;
  cin >> n >> s;
  vector<ll> ans;
  for(ll i = n; i >= 1; i--) {
    if(s - i >= 0) {
      ans.push_back(i);
      s -= i;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for(int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
0