Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <stack>
#include <map>
#include <math.h>
#include <cmath>
#include <string.h>
#include <numeric>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 1e6, M=1e6+1, NN=1e8 , MX = 1e9;
const ll MXL=1e18 , MOD = 1e9 + 7, MD= 998244353;
int a[N], deg[N]; 
int main(){
    //freopen("input.txt", "r", stdin);
    ll x, ans;
    cin >> x;
    ll l=1, r=x;
    while( l<=r ){
        ll mid = l+ (r-l)/2;
        if( mid*(mid+1) <= 2*x ){
            l= mid+1;
            ans = mid;
        }
        else
            r=mid-1;
    } 
    cout << ans <<"\n";
    ll rem=x;
    for(ll i=1 ; i<ans ; i++ ){
        cout << i <<" ";
        rem-=i;
    }
    cout <<  rem;
    return 0 ;
}
Copy
Want More! Rand()
GNU G++17
1100 ms
61.3 MB
Time Limit Exceeded