prithivMLmods/Coder-Stat huggingface dataset:
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll x[k];
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x[a] += b;
  }
  ll c = 0;
  for (int i = 0; i < 100001; i++) {
    c += x[i];
    if (c >= k) {
      cout << i;
      return 0;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll x[100001] = {};
  for (ll i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x[a] += b;
  }
  ll c = 0;
  for (int i = 0; i < 100001; i++) {
    c += x[i];
    if (c >= k) {
      cout << i;
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> cnt(100001, 0);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    cnt[a] += b;
  }

  rep(i, 100001) {
    k -= cnt[i];
    if (k <= 0) {
      cout << i << endl;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> cnt(100001, 0);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    cnt[a] += b;
  }

  rep(i, 100001) {
    k -= cnt[i];
    if (k <= 0) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#define ll long long
using namespace std;
static const int INF = (1 << 21);

ll int a[100001] = {0};

int main() {
  ll int N, K;
  cin >> N >> K;
  for (ll int i = 0; i < N; i++) {
    int j, k;
    cin >> j >> k;
    a[j] += k;
  }
  ll int i = 0, j = 1;
  while (i < K) {
    if (a[j] == 0)
      j++;
    else {
      a[j]--;
      i++;
    }
  }
  cout << j << endl;
}

Fixed submission:
#include "bits/stdc++.h"
#define ll long long
using namespace std;
static const int INF = (1 << 21);

ll int a[100001] = {0};

int main() {
  ll int N, K;
  cin >> N >> K;
  for (ll int i = 0; i < N; i++) {
    int j, k;
    cin >> j >> k;
    a[j] += k;
  }
  ll int i = 0, j = 1;
  while (i < K) {
    if (a[j] == 0)
      j++;
    else {
      i += a[j];
      a[j] = 0;
    }
  }
  cout << j << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<P> vec;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vec.pb(mk(a, b));
  }
  sort(vec.begin(), vec.end());
  ll sum = 0;
  int i = 0;
  while (sum < k) {
    sum += vec[i].second;
    i++;
  }
  cout << vec[i - 1].first << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const *argv[]) {
  int n;
  ll k;
  cin >> n >> k;
  vector<P> vec;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vec.pb(mk(a, b));
  }
  sort(vec.begin(), vec.end());
  ll sum = 0;
  int i = 0;
  while (sum < k) {
    sum += vec[i].second;
    i++;
  }
  cout << vec[i - 1].first << endl;
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<pair<int, int>> data(n);

  for (int i = 0; i < n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    pair<int, int> p = make_pair(ai, bi);
    data.at(i) = p;
  }

  sort(data.begin(), data.end());

  int64_t sum = 0;

  int i = 0;

  while (sum < k) {
    sum += data.at(i).second;
    i++;
  }

  int answer = data.at(i - 1).first;

  cout << answer << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n, k;
  cin >> n >> k;

  vector<pair<int, int>> data(n);

  for (int i = 0; i < n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    pair<int, int> p = make_pair(ai, bi);
    data.at(i) = p;
  }

  sort(data.begin(), data.end());

  int64_t sum = 0;

  int i = 0;

  while (sum < k) {
    sum += data.at(i).second;
    i++;
  }

  int answer = data.at(i - 1).first;

  cout << answer << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  ll maxN = 100000 + 1, sum = 0;
  vector<ll> num(maxN, 0);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    num[a] += b;
  }
  for (ll i = 0; i < maxN; i++) {
    sum += num[i];
    if (k <= sum) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  ll maxN = 100000 + 1, sum = 0;
  vector<ll> num(maxN, 0);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    num[a] += b;
  }
  for (ll i = 0; i < maxN; i++) {
    sum += num[i];
    if (k <= sum) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> v(N);
  for (int i = 0; i < N; i++)
    cin >> v.at(i).first >> v.at(i).second;

  sort(v.begin(), v.end());
  int j = -1;
  while (K > 0) {
    j++;
    K -= v.at(j).second;
  }
  cout << v.at(j).first << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  vector<pair<int, int>> v(N);
  for (int i = 0; i < N; i++)
    cin >> v.at(i).first >> v.at(i).second;

  sort(v.begin(), v.end());
  int j = -1;
  while (K > 0) {
    j++;
    K -= v.at(j).second;
  }
  cout << v.at(j).first << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, k;
  cin >> n >> k;
  vector<ll> v(1e5 + 5);

  int ans;
  rep(i, n) {
    int a, b;
    cin >> a >> b;

    v[a] += b;
  }

  rep(i, 1e5 + 5) {
    if (k <= v[i]) {
      ans = i;
      break;
    }
    k -= v[i];
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k;
  cin >> n >> k;
  vector<ll> v(1e5 + 5);

  int ans;
  rep(i, n) {
    int a, b;
    cin >> a >> b;

    v[a] += b;
  }

  rep(i, 1e5 + 5) {
    if (k <= v[i]) {
      ans = i;
      break;
    }
    k -= v[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int N, K;
  int64_t a, b;

  cin >> N >> K;

  vector<int64_t> ab(200000, 0);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    ab[a - 1] += b;
  }

  b = 0;
  for (int i = 0;; i++) {
    b += ab[i];
    if (b >= K) {
      a = i + 1;
      break;
    }
  }

  cout << a << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int64_t N, K;
  int64_t a, b;

  cin >> N >> K;

  vector<int64_t> ab(200000, 0);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    ab[a - 1] += b;
  }

  b = 0;
  for (int i = 0;; i++) {
    b += ab[i];
    if (b >= K) {
      a = i + 1;
      break;
    }
  }

  cout << a << "\n";

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int main() {
  // 三日目
  ll n = 0, k = 0;
  ll a = 0, b = 0;
  ll imadoko = 0, f = 0;
  map<ll, ll> ab;
  vector<ll> type;
  cin >> n >> k;
  rep(i, n) {
    cin >> a >> b;
    if (ab[a] == 0) {
      type.push_back(a);
    }
    ab[a] += b;
  }
  sort(type.begin(), type.end());
  while (imadoko <= k) {
    imadoko += ab[type[f]];
    f++;
  }
  cout << type[f - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int main() {
  // 三日目
  ll n = 0, k = 0;
  ll a = 0, b = 0;
  ll imadoko = 0, f = 0;
  map<ll, ll> ab;
  vector<ll> type;
  cin >> n >> k;
  rep(i, n) {
    cin >> a >> b;
    if (ab[a] == 0) {
      type.push_back(a);
    }
    ab[a] += b;
  }
  sort(type.begin(), type.end());
  while (imadoko < k) {
    imadoko += ab[type[f]];
    f++;
  }
  cout << type[f - 1] << endl;
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  cin >> n >> k;
  vector<long long> c(100000);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    c.at(a - 1) += b;
  }
  for (int i = 0; i < 100000; i++) {
    if (c.at(i) == 0)
      continue;
    else if (k > c.at(i)) {
      k -= c.at(i);
    } else if (k <= c.at(i)) {
      cout << i + 1 << endl;
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
  cin >> n >> k;
  vector<long long> c(100000);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    c.at(a - 1) += b;
  }
  for (int i = 0; i < 100000; i++) {
    if (c.at(i) == 0)
      continue;
    else if (k > c.at(i)) {
      k -= c.at(i);
    } else if (k <= c.at(i)) {
      cout << i + 1 << endl;
      break;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> num(100001, 0);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    num[a] += b;
  }
  long int count = 0;
  for (int i = 1; i <= 100000; i++) {
    count += num[i];
    if (count >= k) {
      cout << i << endl;
      break;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long int k;
  cin >> n >> k;
  vector<long long int> num(100001, 0);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    num[a] += b;
  }
  long int count = 0;
  for (int i = 1; i <= 100000; i++) {
    count += num[i];
    if (count >= k) {
      cout << i << endl;
      break;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long cnt[100001];
int main() {
  int n, k;
  cin >> n >> k;
  int a, b;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    cnt[a] += b;
  }
  long long sum = 0;
  for (int i = 1; sum < k; ++i) {
    if (sum + cnt[i] >= k) {
      cout << i << endl;
      break;
    }
    sum += cnt[i];
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long cnt[100001];
int main() {
  long long n, k;
  cin >> n >> k;
  int a, b;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    cnt[a] += b;
  }
  long long sum = 0;
  for (int i = 1; sum < k; ++i) {
    if (sum + cnt[i] >= k) {
      cout << i << endl;
      break;
    }
    sum += cnt[i];
  }
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> ppair;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ppair> ab(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end(), greater<ppair>());
  ll k = 0;
  int ans;
  for (int i = 0; i < N; i++) {
    ppair now = ab.back();
    ab.pop_back();
    int tmp = now.second;
    for (int j = 0; j < tmp; j++) {
      ans = now.first;
      k++;
      if (k == K) {
        break;
      }
    }
    if (k == K) {
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> ppair;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ppair> ab(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end(), greater<ppair>());
  ll k = 0;
  int ans;
  for (int i = 0; i < N; i++) {
    ppair now = ab.back();
    ab.pop_back();
    int tmp = now.second;
    // cout << tmp << endl;
    if (k + tmp < K) {
      k += tmp;
      continue;
    }
    for (int j = 0; j < tmp; j++) {
      ans = now.first;
      k++;
      if (k == K) {
        break;
      }
    }
    if (k == K) {
      break;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int N, K;
long long ans[100002] = {};

int main() {
  cin >> N >> K;
  int a[N], b[N];
  rep(i, N) {
    cin >> a[i] >> b[i];
    ans[a[i]] += b[i];
  }
  rep(i, 100002) {
    K -= ans[i];
    if (K <= 0) {
      out(i);
      return 0;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

long long N, K;
long long ans[100002] = {};

int main() {
  cin >> N >> K;
  int a[N], b[N];
  rep(i, N) {
    cin >> a[i] >> b[i];
    ans[a[i]] += b[i];
  }
  rep(i, 100002) {
    K -= ans[i];
    if (K <= 0) {
      out(i);
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> cnt(100001);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a] += b;
  }

  long long c = 0;
  for (int i = 0; i < 100001; i++) {
    c += cnt[i];
    if (c >= K) {
      cout << i << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> cnt(100001);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a] += b;
  }

  long long c = 0;
  for (int i = 0; i < 100001; i++) {
    c += cnt[i];
    if (c >= K) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm> // swap,sort,binary_search
#include <cassert>
#include <cmath>
#include <functional> // std::greater
#include <iomanip>    //cout<<setprecision
#include <iostream>
#include <list> //list
#include <map>  //map
#include <numeric>
#include <queue> //queue
#include <regex>
#include <set>     //set
#include <sstream> //string stream its useful!
#include <string>
#include <utility> //pair
#include <vector>  // vector

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
ll W = 1000000007;

using namespace std;
void omajinai() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  // freopen("txt.csv","r",stdin);
}

class Main {
public:
  Main() {}

  void run() {
    vector<int> X(100001, 0);
    int N;
    ll K;
    cin >> N >> K;
    REP(i, N) {
      int a, b;
      cin >> a >> b;
      X[a] += b;
    }
    int ans = 0;
    while (K > 0) {
      ans++;
      K -= X[ans];
    }
    cout << ans << endl;
  }
};

int main() {
  omajinai();
  Main().run();
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm> // swap,sort,binary_search
#include <cassert>
#include <cmath>
#include <functional> // std::greater
#include <iomanip>    //cout<<setprecision
#include <iostream>
#include <list> //list
#include <map>  //map
#include <numeric>
#include <queue> //queue
#include <regex>
#include <set>     //set
#include <sstream> //string stream its useful!
#include <string>
#include <utility> //pair
#include <vector>  // vector

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
ll W = 1000000007;

using namespace std;
void omajinai() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  // freopen("txt.csv","r",stdin);
}

class Main {
public:
  Main() {}

  void run() {
    vector<ll> X(100001, 0);
    int N;
    ll K;
    cin >> N >> K;
    REP(i, N) {
      int a, b;
      cin >> a >> b;
      X[a] += b;
    }
    int ans = 0;
    while (K > 0) {
      ans++;
      K -= X[ans];
    }
    cout << ans << endl;
  }
};

int main() {
  omajinai();
  Main().run();
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int INF = 2147483647;
const long long MOD = 1e9 + 7;

using namespace std;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<long long> vi(100001, 0);
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    // cout<<x<<vi[x]<<endl;
    vi[x] += y;
  }

  long long ct = 0;
  for (int i = 0; ct < k; i++) {
    ct += vi[i];
    if (ct >= k) {
      cout << i;
      return 0;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int INF = 2147483647;
const long long MOD = 1e9 + 7;

using namespace std;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long k;
  cin >> n >> k;
  vector<long long> vi(100001, 0);
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    // cout<<x<<vi[x]<<endl;
    vi[x] += y;
  }

  long long ct = 0;
  for (int i = 0; ct < k; i++) {
    ct += vi[i];
    if (ct >= k) {
      cout << i;
      return 0;
    }
  }

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
int c[SIZE];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  int a, b;

  rep(i, n) {
    cin >> a >> b;
    c[a] += b;
  }

  for (int i = 1; i <= SIZE; i++) {
    k -= c[i];
    if (k <= 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Fixed submission:
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
ll c[SIZE];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  int a, b;

  rep(i, n) {
    cin >> a >> b;
    c[a] += b;
  }

  for (int i = 1; i <= SIZE; i++) {
    k -= c[i];
    if (k <= 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using namespace std;
typedef long long li;
#define chmin(a, b) (a > (b) ? a = (b), 1 : 0)
#define abs(n) max((n), -(n))
#define dist(a, b) max((a) - (b), (b) - (a))
#define chmax(a, b) (a < (b) ? a = (b), 1 : 0)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define MOD 1000000000
#define rep(i, n) for (int i = 0; i < (n); i++)

#define df 0
template <class T> void print(const T &t) { cout << t << "\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts))
    cout << " ";
  print(ts...);
}
// Container コンテナ型, map以外
template <template <class...> class Ctn, class T>
std::ostream &operator<<(std::ostream &os, const Ctn<T> &v) {
  // ここでストリームに obj を書き込みます。
  auto itr = v.begin();
  while (itr != v.end()) {
    if (itr != v.begin())
      cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main() {
  int n;
  li k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  int t = 0, i = 0;
  while (t < k) {
    t += v[i++].second;
  }
  print(v[i - 1].first);
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using namespace std;
typedef long long li;
#define chmin(a, b) (a > (b) ? a = (b), 1 : 0)
#define abs(n) max((n), -(n))
#define dist(a, b) max((a) - (b), (b) - (a))
#define chmax(a, b) (a < (b) ? a = (b), 1 : 0)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define MOD 1000000000
#define rep(i, n) for (int i = 0; i < (n); i++)

#define df 0
template <class T> void print(const T &t) { cout << t << "\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts))
    cout << " ";
  print(ts...);
}
// Container コンテナ型, map以外
template <template <class...> class Ctn, class T>
std::ostream &operator<<(std::ostream &os, const Ctn<T> &v) {
  // ここでストリームに obj を書き込みます。
  auto itr = v.begin();
  while (itr != v.end()) {
    if (itr != v.begin())
      cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main() {
  int n;
  li k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  li t = 0, i = 0;
  while (t < k) {
    t += v[i++].second;
  }
  print(v[i - 1].first);
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

const int MAXN = 1e5 + 10;

int N;
long long K;

int freq[MAXN];

int main() {
  scanf("%d %lld", &N, &K);

  for (int i = 1; i <= N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    freq[a] += b;
  }

  int i = 1;
  long long k = 0;

  while (k + freq[i] < K) {
    k += freq[i];
    i++;
  }

  printf("%d\n", i);
  return 0;
}

Fixed submission:
#include <cstdio>

const int MAXN = 1e5 + 10;

int N;
long long K;
long long freq[MAXN];

int main() {
  scanf("%d %lld", &N, &K);

  for (int i = 1; i <= N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    freq[a] += b;
  }

  int i = 1;
  long long k = 0;

  while (k + freq[i] < K) {
    k += freq[i];
    i++;
  }

  printf("%d\n", i);
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
int main() {
  int N;
  long long K;
  pair<long long, long long> arr[10000];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    arr[i].first = a;
    arr[i].second = b;
  }
  sort(arr, arr + N, compare);
  for (int i = 0; i < N; i++) {
    if (K <= arr[i].second) {
      printf("%lld", arr[i].first);
      break;
    } else
      K -= arr[i].second;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
int main() {
  int N;
  long long K;
  pair<long long, long long> arr[100000];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    arr[i].first = a;
    arr[i].second = b;
  }
  sort(arr, arr + N, compare);
  for (int i = 0; i < N; i++) {
    if (K <= arr[i].second) {
      printf("%lld", arr[i].first);
      break;
    } else
      K -= arr[i].second;
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define lol long long

pair<int, int> a[110000];

int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + N);
  int iti = 0;
  int ans = 0;
  while (K > 0) {
    K -= a[iti].second;
    ans = a[iti].first;
    iti++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define lol long long

pair<int, int> a[110000];

int main() {
  lol N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + N);
  int iti = 0;
  int ans = 0;
  while (K > 0) {
    K -= a[iti].second;
    ans = a[iti].first;
    iti++;
  }
  cout << ans << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define MAX 100000
using namespace std;
int main() {
  long long int data[MAX];
  for (int i = 0; i < MAX; i++) {
    data[i] = 0;
  }
  long long int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    data[a - 1] += b;
  }
  int count = 0;
  for (int i = 0;; i++) {
    count += data[i];
    if (count >= m) {
      cout << i + 1 << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#define MAX 100000
using namespace std;
int main() {
  long long int data[MAX];
  for (int i = 0; i < MAX; i++) {
    data[i] = 0;
  }
  long long int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    data[a - 1] += b;
  }
  long long int count = 0;
  for (int i = 0;; i++) {
    count += data[i];
    if (count >= m) {
      cout << i + 1 << endl;
      break;
    }
  }
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(), x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;

int digit(ll x) {
  if (x / 10 == 0)
    return 1;
  return digit(x / 10) + 1;
}

ll gcd(long long a, long long b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

bool is_prime(long long N) {
  if (N == 1)
    return false;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}

ll lcm(ll a, ll b) { return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b); }

double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

///////////////////////////////////////////////////////////////////////////////////

int main() {
  int n, k;
  cin >> n >> k;
  int mx = 100010;
  vector<long long> res(mx, 0);
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    res[a] += b;
  }

  long long ans = 0;
  for (int i = 1; i < 100010; i++) {
    ans += res[i];
    if (ans >= k) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(), x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;

int digit(ll x) {
  if (x / 10 == 0)
    return 1;
  return digit(x / 10) + 1;
}

ll gcd(long long a, long long b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

bool is_prime(long long N) {
  if (N == 1)
    return false;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}

ll lcm(ll a, ll b) { return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b); }

double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

///////////////////////////////////////////////////////////////////////////////////

int main() {
  long long n, k;
  cin >> n >> k;
  int mx = 100010;
  vector<long long> res(mx, 0);
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    res[a] += b;
  }

  long long ans = 0;
  for (int i = 1; i < 100010; i++) {
    ans += res[i];
    if (ans >= k) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int cc[100005] = {0};
int main() {
  int n;
  cin >> n;
  lint k;
  cin >> k;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    cc[a] += b;
  }
  int i = 0;
  while (k > cc[i]) {
    k -= cc[i];
    i++;
  }
  cout << i << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
lint cc[100005] = {0};
int main() {
  int n;
  cin >> n;
  lint k;
  cin >> k;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    cc[a] += b;
  }
  int i = 0;
  while (k > cc[i]) {
    k -= cc[i];
    i++;
  }
  cout << i << endl;
  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int ix = 0; ix < n; ix++) {
    int x, y;
    cin >> x >> y;
    a.at(ix) = make_pair(x, y);
  }
  sort(a.begin(), a.end());
  ll cnt = 0, ans = -1;
  int i = 0;
  while (cnt <= k) {
    cnt += a.at(i).second;
    if (cnt >= k)
      ans = a.at(i).first;
    i++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int ix = 0; ix < n; ix++) {
    int x, y;
    cin >> x >> y;
    a.at(ix) = make_pair(x, y);
  }
  sort(a.begin(), a.end());
  ll cnt = 0, ans = -1;
  int i = 0;
  while (cnt < k) {
    cnt += a.at(i).second;
    if (cnt >= k)
      ans = a.at(i).first;
    i++;
  }
  cout << ans << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int ix = 0; ix < n; ix++) {
    int x, y;
    cin >> x >> y;
    a.at(ix) = make_pair(x, y);
  }
  sort(a.begin(), a.end());
  int cnt = 0, i = 0, ans = -1;
  if (cnt == k) {
    cout << a.at(0).first << endl;
  }
  while (1) {
    cnt += a.at(i).second;
    if (cnt >= k) {
      ans = a.at(i).first;
      break;
    }
    i++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int ix = 0; ix < n; ix++) {
    int x, y;
    cin >> x >> y;
    a.at(ix) = make_pair(x, y);
  }
  sort(a.begin(), a.end());
  ll cnt = 0, ans = -1;
  int i = 0;
  while (1) {
    cnt += a.at(i).second;
    if (cnt >= k) {
      ans = a.at(i).first;
      break;
    }
    i++;
  }
  cout << ans << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int> vec(100000, 0);
  int64_t N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    vec[a] += b;
  }

  for (int i = 0; true; i++) {
    K -= vec[i];
    if (K <= 0) {
      cout << i << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int64_t> vec(100000, 0);
  int64_t N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    vec[a] += b;
  }

  for (int i = 0; true; i++) {
    K -= vec[i];
    if (K <= 0) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> arr;

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    arr.emplace_back(a, b);
  }
  sort(arr.begin(), arr.end());
  int ptr = 0;
  while (true) {
    k -= arr[ptr].second;
    if (k <= 0) {
      cout << arr[ptr].first << endl;
      break;
    } else
      ++ptr;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> arr;

int main() {
  int n;
  long long k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    arr.emplace_back(a, b);
  }
  sort(arr.begin(), arr.end());
  int ptr = 0;
  while (true) {
    k -= arr[ptr].second;
    if (k <= 0) {
      cout << arr[ptr].first << endl;
      break;
    } else
      ++ptr;
  }

  return 0;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> num(n);
  ll a, b;
  rep(i, n) {
    cin >> a >> b;
    num[a - 1] += b;
  }
  ll sum = 0;
  rep(i, 100000) {
    sum += num[i];
    if (sum >= k) {
      cout << i + 1;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> num(100010);
  ll a, b;
  rep(i, n) {
    cin >> a >> b;
    num[a - 1] += b;
  }
  ll sum = 0;
  rep(i, 100000) {
    sum += num[i];
    if (sum >= k) {
      cout << i + 1;
      return 0;
    }
  }
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

using ll = long long int;

pair<int, int> arr[100010];

int main() {

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;

    arr[i].first = a;
    arr[i].second = b;
  }

  sort(arr, arr + n);

  int result = 0;
  while (m > 0) {

    // cout << m << endl;
    m -= arr[result].second;
    result++;
  }
  cout << arr[result - 1].first << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

using ll = long long int;

pair<int, int> arr[100010];

int main() {

  ll n, m;
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;

    arr[i].first = a;
    arr[i].second = b;
  }

  sort(arr, arr + n);

  int result = 0;
  while (m > 0) {

    // cout << m << endl;
    m -= arr[result].second;
    result++;
  }
  cout << arr[result - 1].first << endl;
}
Problem p03721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, K;
  cin >> N >> K;
  long long a[110000], x, y;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    a[i] = 100000 * x + y - 1;
  }
  sort(a, a + N);
  int i = 0;
  while (K > 0) {
    K -= a[i] % 100000 + 1;
    i++;
  }
  cout << a[i - 1] / 100000;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long N, K;
  cin >> N >> K;
  long long a[110000], x, y;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    a[i] = 100000 * x + y - 1;
  }
  sort(a, a + N);
  int i = 0;
  while (K > 0) {
    K -= a[i] % 100000 + 1;
    i++;
  }
  cout << a[i - 1] / 100000;
}
Problem p03722 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
const int M = 1010;
typedef long long ll;
int a[M], b[M], c[M];
ll ans[M];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = -10000000000000;
  }
  ans[1] = 0;
  for (int i = 1; i <= 10 * n; i++) {
    for (int j = 0; j < m; j++) {
      int u = a[j], v = b[j];
      ans[v] = max(ans[v], ans[u] + c[j]);
    }
  }
  ll pre = ans[n];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      int u = a[j], v = b[j];
      ans[v] = max(ans[v], ans[u] + c[j]);
    }
  }
  if (pre != ans[n])
    cout << "inf" << endl;
  else
    cout << ans[n] << endl;
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
const int M = 2010;
typedef long long ll;
int a[M], b[M], c[M];
ll ans[M];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = -10000000000000;
  }
  ans[1] = 0;
  for (int i = 1; i <= 10 * n; i++) {
    for (int j = 0; j < m; j++) {
      int u = a[j], v = b[j];
      ans[v] = max(ans[v], ans[u] + c[j]);
    }
  }
  ll pre = ans[n];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      int u = a[j], v = b[j];
      ans[v] = max(ans[v], ans[u] + c[j]);
    }
  }
  if (pre != ans[n])
    cout << "inf" << endl;
  else
    cout << ans[n] << endl;
  return 0;
}
Problem p03722 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF = -1e15;
struct edge {
  int from, to;
  ll cost;

  edge(int f, int t, ll c) : from(f), to(t), cost(c) {}
};

int N, M;
vector<edge> e;
ll dist[1001];

int main() {
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    e.push_back(edge(a, b, c));
  }

  fill(dist, dist + N, INF);
  dist[0] = 0;
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < e.size(); i++) {
      if (dist[i] == INF)
        continue;

      if (dist[e[i].to] < dist[e[i].from] + e[i].cost) {
        dist[e[i].to] = dist[e[i].from] + e[i].cost;
        //	cout <<dist[e[i].to]<<endl;
      }
    }
  }

  ll heiro = dist[N - 1];
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < e.size(); i++) {
      if (dist[e[i].from] == INF)
        continue;

      if (dist[e[i].to] < dist[e[i].from] + e[i].cost) {
        dist[e[i].to] = dist[e[i].from] + e[i].cost;
        //	cout <<dist[e[i].to]<<endl;
      }
    }
  }
  if (heiro >= dist[N - 1]) {
    cout << dist[N - 1] << endl;
  } else
    cout << "inf" << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF = -1e15;
struct edge {
  int from, to;
  ll cost;

  edge(int f, int t, ll c) : from(f), to(t), cost(c) {}
};

int N, M;
vector<edge> e;
ll dist[1001];

int main() {
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    e.push_back(edge(a, b, c));
  }

  fill(dist, dist + N, INF);
  dist[0] = 0;
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < e.size(); i++) {
      if (dist[e[i].from] == INF)
        continue;

      if (dist[e[i].to] < dist[e[i].from] + e[i].cost) {
        dist[e[i].to] = dist[e[i].from] + e[i].cost;
        //	cout <<dist[e[i].to]<<endl;
      }
    }
  }

  ll heiro = dist[N - 1];
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < e.size(); i++) {
      if (dist[e[i].from] == INF)
        continue;

      if (dist[e[i].to] < dist[e[i].from] + e[i].cost) {
        dist[e[i].to] = dist[e[i].from] + e[i].cost;
        //	cout <<dist[e[i].to]<<endl;
      }
    }
  }
  if (heiro >= dist[N - 1]) {
    cout << dist[N - 1] << endl;
  } else
    cout << "inf" << endl;
}
Problem p03722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

int64_t solve();

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  using pi = std::pair<int64_t, int>;
  using vpi = std::vector<pi>;
  using vvpi = std::vector<vpi>;
  vvpi edges(N);
  std::vector<std::vector<int>> rev_edges(N);
  for (int i{}; i < M; i++) {
    int a, b;
    int64_t c;
    scanf("%d%d%lld", &a, &b, &c);
    a--;
    b--;
    edges[a].push_back({c, b});
    rev_edges[b].push_back(a);
  }
  std::vector<int64_t> distance(N, LLONG_MIN);
  distance[0] = 0;
  for (int i{}; i < N; i++)
    for (int j{}; j < N; j++)
      if (distance[j] != LLONG_MIN)
        for (auto &e : edges[j])
          distance[e.second] =
              std::max(distance[e.second], distance[j] + e.first);

  std::vector<int64_t> check(distance);
  for (int i{}; i < N; i++)
    for (int j{}; j < N; j++)
      if (check[j] != LLONG_MIN)
        for (auto &e : edges[j])
          check[e.second] = std::max(check[e.second], check[j] + e.first);
  std::vector<bool> visited(N);
  std::queue<int> que;
  visited[N - 1] = true;
  que.push(N - 1);
  while (!que.empty()) {
    auto now{que.front()};
    que.pop();
    if (check[now] != distance[now]) {
      puts("inf");
      return 0;
    }
    for (auto &e : rev_edges[now]) {
      if (visited[e])
        continue;
      que.push(e);
    }
  }
  printf("%lld\n", distance[N - 1]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

int64_t solve();

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  using pi = std::pair<int64_t, int>;
  using vpi = std::vector<pi>;
  using vvpi = std::vector<vpi>;
  vvpi edges(N);
  std::vector<std::vector<int>> rev_edges(N);
  for (int i{}; i < M; i++) {
    int a, b;
    int64_t c;
    scanf("%d%d%lld", &a, &b, &c);
    a--;
    b--;
    edges[a].push_back({c, b});
    rev_edges[b].push_back(a);
  }
  std::vector<int64_t> distance(N, LLONG_MIN);
  distance[0] = 0;
  for (int i{}; i < N; i++)
    for (int j{}; j < N; j++)
      if (distance[j] != LLONG_MIN)
        for (auto &e : edges[j])
          distance[e.second] =
              std::max(distance[e.second], distance[j] + e.first);

  std::vector<int64_t> check(distance);
  for (int i{}; i < N; i++)
    for (int j{}; j < N; j++)
      if (check[j] != LLONG_MIN)
        for (auto &e : edges[j])
          check[e.second] = std::max(check[e.second], check[j] + e.first);
  std::vector<bool> visited(N);
  std::queue<int> que;
  visited[N - 1] = true;
  que.push(N - 1);
  while (!que.empty()) {
    auto now{que.front()};
    que.pop();
    if (check[now] != distance[now]) {
      puts("inf");
      return 0;
    }
    for (auto &e : rev_edges[now]) {
      if (visited[e])
        continue;
      que.push(e);
      visited[e] = true;
    }
  }
  printf("%lld\n", distance[N - 1]);

  return 0;
}