結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー Shirotsume
提出日時 2022-07-19 16:02:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 4,539 ms
コンパイル使用メモリ 251,456 KB
最終ジャッジ日時 2025-01-30 11:06:01
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
using ll = long long;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)

int main(void)
{
    ll n, s;
    cin >> n >> s;
    ll summ = 0;
    vector<int> ans;

    for(int i = n; i > 0; i--){
        if(summ + i <= s){
            ans.push_back(i);
            summ += i;
        } 
    }
    reverse(all(ans));
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    return 0;
}

0