Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <experimental/any>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using experimental::any;

#define SPEEDY                                                                 \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ARREP(i, n, X)                                                         \
  for (int i = 0; i < (n); i++)                                                \
  cin >> X[i]
#define FOR(i, X, n) for (int i = (X); i < (n); i++)
#define EREP(i, n) for (int i = 1; i <= n; i++)
#define BitFOR(N) REP(Bit, 1 << (N))

// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define DEB2(X) cout << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define TFDEB(f) (f) ? cout << "true " : cout << "false ";
#define FORDEB(n, X)                                                           \
  for (int i = 0; i < (n); i++)                                                \
  ARDEB(i, X)
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define DEB2(X)                                                                \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define TFDEB(f)                                                               \
  {}
#define FORDEB(n, X)                                                           \
  {}
#define END                                                                    \
  {}
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define ALL(X) X.begin(), X.end()
struct edge {
  int to, cost;
};
// struct edge{int from,cost,to;};
struct P2 {
  int x, y;
};
#define BIT(Bit, n) bitset<n>(Bit)
#define Endl endl

const int MOD7 = 1000000007;
const int INF = 100000000;
const int SET = 1000;

int main() {
  int n, m, a[100000], b[100000], num[100010] = {}, ans = 0, last;
  bool f = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    num[a[i] - 1] += b[i];
  }
  REP(i, 5) { ARDEB(i, num) END }
  for (int i = 0; i < 1000000; i++) {
    DEB(i) END if (i != 0) {
      num[i] += num[i - 1];
      DEB(i) END
    }
    if (num[i] >= m) {
      cout << i + 1 << endl;
      return 0;
    }
    if (i < 5) {
      ARDEB(i, num) END
    }
  }
  return 0;
}
// 1,2,4,8,16

Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <experimental/any>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using experimental::any;

#define SPEEDY                                                                 \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ARREP(i, n, X)                                                         \
  for (int i = 0; i < (n); i++)                                                \
  cin >> X[i]
#define FOR(i, X, n) for (int i = (X); i < (n); i++)
#define EREP(i, n) for (int i = 1; i <= n; i++)
#define BitFOR(N) REP(Bit, 1 << (N))

// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define DEB2(X) cout << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define TFDEB(f) (f) ? cout << "true " : cout << "false ";
#define FORDEB(n, X)                                                           \
  for (int i = 0; i < (n); i++)                                                \
  ARDEB(i, X)
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define DEB2(X)                                                                \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define TFDEB(f)                                                               \
  {}
#define FORDEB(n, X)                                                           \
  {}
#define END                                                                    \
  {}
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define ALL(X) X.begin(), X.end()
struct edge {
  int to, cost;
};
// struct edge{int from,cost,to;};
struct P2 {
  int x, y;
};
#define BIT(Bit, n) bitset<n>(Bit)
#define Endl endl

const int MOD7 = 1000000007;
const int INF = 100000000;
const int SET = 1000;

int main() {
  ll n, m, a[100000], b[100000], num[100010] = {}, ans = 0, last;
  bool f = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    num[a[i] - 1] += b[i];
  }
  REP(i, 5) { ARDEB(i, num) END }
  for (int i = 0; i < 1000000; i++) {
    DEB(i) END if (i != 0) {
      num[i] += num[i - 1];
      DEB(i) END
    }
    if (num[i] >= m) {
      cout << i + 1 << endl;
      return 0;
    }
    if (i < 5) {
      ARDEB(i, num) END
    }
  }
  return 0;
}
// 1,2,4,8,16