結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー srjywrdnprkt
提出日時 2023-05-13 03:22:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 107,296 KB
最終ジャッジ日時 2025-02-12 23:49:05
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, S;
    cin >> N >> S;
    vector<ll> v;

    for (ll i=N; i>=1; i--){
        if (S >= i){
            S -= i;
            v.push_back(i);
        }
    }

    if (S > 0) cout << -1 << endl;
    else{
        reverse(v.begin(), v.end());
        cout << v.size() << endl;
        for (auto x : v) cout << x << " ";
        cout << endl;
    }

    return 0;
}
0