Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll x,sum= 0;
    cin>>x;
    vector <ll> v;
    if(x == 2){
        cout<<1<<endl;
        cout<<2<<endl;
        return 0;
    }
    ll i = 0;
    while(x){
        if(x < i+1){
            v[i-1]+=x;
            x = 0;
        }
        else {
            v.push_back(i+1);
            x-=i+1;
            sum++;
        }
    i++;
    }

    cout<<sum<<endl;
    for(ll i = 0 ; i < v.size(); i++){
        if(i)
            cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
    return 0 ;
}
Copy
Want More! sarah_alsharif_
GNU G++17
110 ms
22.3 MB
Accepted