Source Code
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    map<ll,bool>vis;
    vector<ll> v;
    for(ll i=1;i<=n;i++){
        if(n-i>=0 && vis[n-i]==0){
           vis[i]=1;
           v.push_back(i);
           n-=i;
        }
        else {
            if(n>0)v.push_back(n);
            break; 
        }
    }
    cout<<v.size()<<'\n';
    for(auto x:v){
        cout<<x<<" ";
    }
    
}
Copy
Want More! Ahmed_Allawati
GNU G++17
1046 ms
198.8 MB
Time Limit Exceeded