Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n)-1; i >= 0; i--)

#define DEBUG(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define PR0(A, n)                                                              \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FORN(_, n) cout << A[_] << ' ';                                            \
    cout << endl;                                                              \
  }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL &x) { return scanf("%lld", &x); }

int GI(int &x) { return scanf("%d", &x); }

LL n, a, b, k;
vector<pair<LL, LL>> dat;
int main() {
  GLL(n);
  GLL(k);
  FORN(i, n) {
    GLL(a);
    GLL(b);

    dat.PB(MP(a, b));
  }
  sort(dat.begin(), dat.end());

  int cnt = 0;
  int i = 0;
  while (cnt < k) {
    cnt += dat[i].SS;
    i += 1;
  }

  printf("%lld\n", dat[i - 1].FF);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n)-1; i >= 0; i--)

#define DEBUG(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define PR0(A, n)                                                              \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FORN(_, n) cout << A[_] << ' ';                                            \
    cout << endl;                                                              \
  }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL &x) { return scanf("%lld", &x); }

int GI(int &x) { return scanf("%d", &x); }

LL n, a, b, k;
vector<pair<LL, LL>> dat;
int main() {
  GLL(n);
  GLL(k);
  FORN(i, n) {
    GLL(a);
    GLL(b);

    dat.PB(MP(a, b));
  }
  sort(dat.begin(), dat.end());

  LL cnt = 0;
  int i = 0;
  while (cnt < k) {
    cnt += dat[i].SS;
    i += 1;
  }

  printf("%lld\n", dat[i - 1].FF);

  return 0;
}