Problem p03779 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for (ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point {
  int x, y;
};

bool vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return true;
  } else { // 発見できなかったとき
    return false;
  }
}

ll factorial(ll N) {
  ll ans = 1;
  llRep(i, N) { ans *= i; }
  return ans;
}

vector<ll> Eratosthenes(ll N) {
  bool arr[N + 1];
  // initialization
  arr[0] = false;
  arr[1] = false;
  for (ll i = 2; i < N + 1; i++) {
    arr[i] = true;
  }
  // eratosthenes
  for (ll i = 2; i <= sqrt(N); i++) {
    if (arr[i]) {
      for (ll j = 0; i * (j + 2) <= N; j++) {
        arr[i * (j + 2)] = false; // not prime number
      }
    }
  }
  vector<ll> prime;
  llRep(i, N) {
    if (arr[i] == true) {
      prime.push_back(i);
    }
  }
  return prime;
}

int main() {
  ll X;
  cin >> X;
  // dp[i][j]:iまでで合計jになるものがあるかどうか
  bool dp[X + 2][X * (X + 1) / 2 + 2];
  // init
  llrep(i, X + 2) {
    llrep(j, X * (X + 1) / 2 + 2) { dp[i][j] = false; }
  }
  // dp
  llrep(i, X + 1) {
    llrep(j, i * (i + 1) / 2 + 1) {
      if (i == 0 && j == 0)
        dp[i][j] = true;
      else if (i > 0) {
        if (j >= i)
          dp[i][j] = dp[i - 1][j] || dp[i - 1][j - i];
        else
          dp[i][j] = dp[i - 1][j];
      }
    }
    if (dp[i][X] == true) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for (ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point {
  int x, y;
};

bool vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return true;
  } else { // 発見できなかったとき
    return false;
  }
}

ll factorial(ll N) {
  ll ans = 1;
  llRep(i, N) { ans *= i; }
  return ans;
}

vector<ll> Eratosthenes(ll N) {
  bool arr[N + 1];
  // initialization
  arr[0] = false;
  arr[1] = false;
  for (ll i = 2; i < N + 1; i++) {
    arr[i] = true;
  }
  // eratosthenes
  for (ll i = 2; i <= sqrt(N); i++) {
    if (arr[i]) {
      for (ll j = 0; i * (j + 2) <= N; j++) {
        arr[i * (j + 2)] = false; // not prime number
      }
    }
  }
  vector<ll> prime;
  llRep(i, N) {
    if (arr[i] == true) {
      prime.push_back(i);
    }
  }
  return prime;
}

int main() {
  ll X;
  cin >> X;
  ll sum = 0;
  llRep(i, X) {
    sum += i;
    if (sum >= X) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}