結果

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    ll s;
    cin >> n >> s;
    vector<int> a;
    for (int i = n; i > 0; i--)
    {
        if (i <= s)
        {
            a.push_back(i);
            s -= i;
        }
    }
    reverse(a.begin(), a.end());
    cout << a.size() << endl;
    for (int i : a)
    {
        cout << i << " ";
    }
    cout << endl;
}
0