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

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n;
  cin >> n;
  priority_queue<l_l, vector<l_l>, greater<l_l>> q;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    q.push(l_l(b, a));
  }
  ll time = 0;
  rep(i, n) {
    time += q.top().second;
    if (time > q.top().first) {
      cout << "No" << endl;
      return 0;
    }
    q.pop();
  }
  cout << "Yes" << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n;
  cin >> n;
  priority_queue<l_l, vector<l_l>, greater<l_l>> q;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    q.push(l_l(b, a));
  }
  ll time = 0;
  rep(i, n) {
    time += q.top().second;
    if (time > q.top().first) {
      cout << "No" << endl;
      return 0;
    }
    q.pop();
  }
  cout << "Yes" << endl;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iomanip>  //小数点以下を表示させる(setprecision())
#include <iostream> //入出力
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x)                                                               \
  cerr << x << " "                                                             \
       << "(L:" << __LINE__ << ")" << '\n'

// DP法
template <class T>
inline bool chmin(T &a, T b) // change minimum
{
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) // change max
{
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

typedef long long ll; // 64bit型

using namespace std;

// const long long INF = 1LL << 60; //無限大の値
int INF = 1000000;

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> task;
  REP(i, N)
  cin >> task[i].second >> task[i].first;

  sort(task.begin(), task.end());
  ll ans = 0;

  REP(i, N) {
    ans += task[i].second;
    if (ans > task[i].first) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iomanip>  //小数点以下を表示させる(setprecision())
#include <iostream> //入出力
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x)                                                               \
  cerr << x << " "                                                             \
       << "(L:" << __LINE__ << ")" << '\n'

// DP法
template <class T>
inline bool chmin(T &a, T b) // change minimum
{
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) // change max
{
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

typedef long long ll; // 64bit型

using namespace std;

// const long long INF = 1LL << 60; //無限大の値
int INF = 1000000;

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> task(N);
  REP(i, N) { cin >> task[i].second >> task[i].first; }

  sort(task.begin(), task.end());
  ll ans = 0;

  REP(i, N) {
    ans += task[i].second;
    if (ans > task[i].first) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
ll read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 5;
struct node {
  ll x, y;
} z[N];
bool cmp(const node a, const node b) {
  if (a.y != b.y)
    return a.y < b.y;
  return a.x < b.x;
}
int main() {
  ll n = rr, sum = 0, end = 0;
  for (int i = 0; i < n; i++) {
    ll x = rr, y = rr;
    sum += x;
    end = max(end, y);
    z[i].x = x;
    z[i].y = y;
  }
  if (end < sum) {
    printf("No\n");
    return 0;
  }
  sort(z, z + n, cmp);
  ll time = 0;
  for (int i = 0; i < n; i++) {

    if (time + z[i].x <= z[i].y)
      time += z[i].x;
    else {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
ll read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 5;
struct node {
  ll x, y;
} z[2 * N];
bool cmp(const node a, const node b) {
  if (a.y != b.y)
    return a.y < b.y;
  return a.x < b.x;
}
int main() {
  ll n = rr, sum = 0, end = 0;
  for (int i = 0; i < n; i++) {
    ll x = rr, y = rr;
    sum += x;
    end = max(end, y);
    z[i].x = x;
    z[i].y = y;
  }
  if (end < sum) {
    printf("No\n");
    return 0;
  }
  sort(z, z + n, cmp);
  ll time = 0;
  for (int i = 0; i < n; i++) {

    if (time + z[i].x <= z[i].y)
      time += z[i].x;
    else {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second)
    return a.second < b.second;
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(ALL(p), compare);
  int time = 0;
  rep(i, n) {
    time += p[i].first;
    if (time > p[i].second) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(ALL(p), compare);
  int time = 0;
  rep(i, n) {
    time += p[i].first;
    if (time > p[i].second) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long a[200010];
long long b[200010];
long long v[500000] = {0};
int main() {
  long long n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    v[b[i]] += a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    if (b[i] == b[i - 1] && i)
      continue;
    // cout<<v[b[i]]<<" "<<ans<<" "<<b[i]<<endl;
    if ((ans + v[b[i]]) > b[i]) {
      cout << "No";
      return 0;
    } else
      ans = ans + v[b[i]];
  }
  cout << "Yes";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long a[200010];
long long b[200010];
map<int, int> v;
int main() {
  long long n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    v[b[i]] += a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    if (b[i] == b[i - 1] && i)
      continue;
    // cout<<v[b[i]]<<" "<<ans<<" "<<b[i]<<endl;
    if ((ans + v[b[i]]) > b[i]) {
      cout << "No";
      return 0;
    } else
      ans = ans + v[b[i]];
  }
  cout << "Yes";
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
// Written By NewbieChd
#include <algorithm>
#include <cctype>
#include <cstdio>
#define int long long
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int f = 0;
  char c;
  while (!isdigit(c = getChar())) {
  }
  do
    f = f * 10 + (c ^ 48);
  while (isdigit(c = getChar()));
  return f;
}

const int maxN = 100003;
int a[maxN], b[maxN], ind[maxN];
inline bool cmp(int x, int y) { return b[x] < b[y]; }

signed main() {
  int n = read(), i, now = 0;
  for (i = 1; i <= n; ++i)
    a[i] = read(), b[i] = read(), ind[i] = i;
  sort(ind + 1, ind + n + 1, cmp);
  for (i = 1; i <= n; ++i)
    if ((now += a[ind[i]]) > b[ind[i]])
      break;
  printf(i > n ? "Yes\n" : "No\n");
  return 0;
}


Fixed submission:
// Written By NewbieChd
#include <algorithm>
#include <cctype>
#include <cstdio>
#define int long long
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int f = 0;
  char c;
  while (!isdigit(c = getChar())) {
  }
  do
    f = f * 10 + (c ^ 48);
  while (isdigit(c = getChar()));
  return f;
}

const int maxN = 200003;
int a[maxN], b[maxN], ind[maxN];
inline bool cmp(int x, int y) { return b[x] < b[y]; }

signed main() {
  int n = read(), i, now = 0;
  for (i = 1; i <= n; ++i)
    a[i] = read(), b[i] = read(), ind[i] = i;
  sort(ind + 1, ind + n + 1, cmp);
  for (i = 1; i <= n; ++i)
    if ((now += a[ind[i]]) > b[ind[i]])
      break;
  printf(i > n ? "Yes\n" : "No\n");
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
  int a, b;
} a[N];
int cmp(node a, node b) { return a.b < b.b; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i].a >> a[i].b;
  sort(a + 1, a + n + 1, cmp);
  int t = 0;
  for (int i = 1; i <= n; i++) {

    t = t + a[i].a;
    // cout<<"t= "<< t<<endl;
    if (t > a[i].b) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  // cout << "Hello world!" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct node {
  int a, b;
} a[N];
int cmp(node a, node b) { return a.b < b.b; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i].a >> a[i].b;
  sort(a + 1, a + n + 1, cmp);
  int t = 0;
  for (int i = 1; i <= n; i++) {

    t = t + a[i].a;
    // cout<<"t= "<< t<<endl;
    if (t > a[i].b) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  // cout << "Hello world!" << endl;
  return 0;
}
Problem p02996 (C++)

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

const int Maxn = 2e5;

int N;
struct Node {
  int t1, t2;
  bool operator<(const Node &rhs) const { return t2 < rhs.t2; }
} A[2 * Maxn + 5];
priority_queue<int> q;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    scanf("%d %d", &A[i].t1, &A[i].t2);
  sort(A + 1, A + N + 1);
  int t = 0, tot = 0;
  for (int i = 1; i <= N; i++) {
    if (t + A[i].t1 <= A[i].t2) {
      tot++;
      t += A[i].t1;
      q.push(A[i].t1);
    } else {
      int maxx = q.top();
      if (A[i].t1 < maxx) {
        q.pop();
        q.push(A[i].t1);
        t = t - maxx + A[i].t1;
      }
    }
  }
  if (tot == N)
    puts("Yes");
  else
    puts("No");
  return 0;
}

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

const int Maxn = 2e5;

int N;
struct Node {
  int t1, t2;
  bool operator<(const Node &rhs) const { return t2 < rhs.t2; }
} A[2 * Maxn + 5];
priority_queue<int> q;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    scanf("%d %d", &A[i].t1, &A[i].t2);
  sort(A + 1, A + N + 1);
  int t = 0, tot = 0;
  for (int i = 1; i <= N; i++) {
    if (t + A[i].t1 <= A[i].t2) {
      tot++;
      t += A[i].t1;
      q.push(A[i].t1);
    } else {
      if (q.empty())
        continue;
      int maxx = q.top();
      if (A[i].t1 < maxx) {
        q.pop();
        q.push(A[i].t1);
        t = t - maxx + A[i].t1;
      }
    }
  }
  if (tot == N)
    puts("Yes");
  else
    puts("No");
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct each {
  int x, y;
} a[N];
bool com(each x, each y) {
  if (x.y == y.y)
    return x.x < y.x;
  return x.y < y.y;
}
int n;
int main() {
  int t = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, com);
  for (int i = 1; i <= n; i++)
    if (t + a[i].x <= a[i].y)
      t += a[i].x;
    else {
      puts("No");
      return 0;
    }
  puts("Yes");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct each {
  int x, y;
} a[N];
bool com(each x, each y) {
  if (x.y == y.y)
    return x.x < y.x;
  return x.y < y.y;
}
int n;
int main() {
  int t = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, com);
  for (int i = 1; i <= n; i++)
    if (t + a[i].x <= a[i].y)
      t += a[i].x;
    else {
      puts("No");
      return 0;
    }
  puts("Yes");
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
const int MAX = 100005;

int main() {
  pair<int, int> A[MAX];
  int N, a, b;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    A[i].first = b;
    A[i].second = a;
  }

  sort(A, A + N);

  int temp = 0;
  for (int i = 0; i < N; ++i) {
    temp += A[i].second;
    if (temp > A[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
const int MAX = 200005;

int main() {
  pair<int, int> A[MAX];
  int N, a, b;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    A[i].first = b;
    A[i].second = a;
  }

  sort(A, A + N);

  int temp = 0;
  for (int i = 0; i < N; ++i) {
    temp += A[i].second;
    if (temp > A[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}
Problem p02996 (C++)

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

int n;
P tasks[101010];

int main() {
  cin >> n;
  rep(i, n) {
    cin >> tasks[i].second >> tasks[i].first;
    if (tasks[i].first < tasks[i].second) {
      cout << "No" << endl;
      return 0;
    }
  }
  sort(tasks, tasks + n);

  ll t = 0;
  rep(i, n) {
    t += (long)tasks[i].second;
    if (t > tasks[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

int n;
P tasks[202020];

int main() {
  cin >> n;
  rep(i, n) {
    cin >> tasks[i].second >> tasks[i].first;
    if (tasks[i].first < tasks[i].second) {
      cout << "No" << endl;
      return 0;
    }
  }
  sort(tasks, tasks + n);

  ll t = 0;
  rep(i, n) {
    t += (long)tasks[i].second;
    if (t > tasks[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long

multimap<int, int> mp;

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int main() {
  IOS;
  fileIO();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    mp.insert({y, x});
  }
  int temp = 0;
  for (auto it : mp) {
    temp += it.second;
    if (temp > it.first) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long

multimap<int, int> mp;

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int main() {
  IOS;
  // fileIO();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    mp.insert({y, x});
  }
  int temp = 0;
  for (auto it : mp) {
    temp += it.second;
    if (temp > it.first) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
// temprates
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

using ll = long long;
using namespace std;

#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i, a, b) for (ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define LREP(i, n) LFOR(i, 0, (ll)(n)-1)
#define REPR(i, n) FORR(i, (int)(n)-1, 0)
#define LREPR(i, n) LFORR(i, (ll)(n)-1, 0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9 + 7;

struct Work {
  ll a;
  ll b;
};
bool operator<(Work w1, Work w2) {
  return (w1.b != w2.b) ? w1.b < w2.b : w1.a < w1.b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<Work> tasks;
  bool ans = true;
  cin >> n;
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    tasks.push_back(Work{a, b});
  }
  sort(tasks.begin(), tasks.end());
  ll t = 0;
  for (int i = 0; i < n; i++) {
    if (t + tasks[i].a <= tasks[i].b) {
      t += tasks[i].a;
    } else {
      ans = false;
      break;
    }
  }

  cout << ((ans) ? "Yes" : "No") << endl;
}


Fixed submission:
// temprates
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

using ll = long long;
using namespace std;

#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i, a, b) for (ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define LREP(i, n) LFOR(i, 0, (ll)(n)-1)
#define REPR(i, n) FORR(i, (int)(n)-1, 0)
#define LREPR(i, n) LFORR(i, (ll)(n)-1, 0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9 + 7;

struct Work {
  ll a;
  ll b;
};
bool operator<(Work w1, Work w2) { return w1.b < w2.b; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<Work> tasks;
  bool ans = true;
  cin >> n;
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    tasks.push_back(Work{a, b});
  }
  sort(tasks.begin(), tasks.end());
  ll t = 0;
  for (int i = 0; i < n; i++) {
    if (t + tasks[i].a <= tasks[i].b) {
      t += tasks[i].a;
    } else {
      ans = false;
      break;
    }
  }

  cout << ((ans) ? "Yes" : "No") << endl;
}
Problem p02996 (C++)

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

int main(void) {
  ll n, i;
  ll t = 0;
  pair<ll, ll> p[100000];
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> p[i].second >> p[i].first;
  }
  sort(p, p + n);

  for (i = 0; i < n; i++) {
    t += p[i].second;
    if (p[i].first < t) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  ll n, i;
  ll t = 0;
  pair<ll, ll> p[200000];
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> p[i].second >> p[i].first;
  }
  sort(p, p + n);

  for (i = 0; i < n; i++) {
    t += p[i].second;
    if (p[i].first < t) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  int n;
  cin >> n;
  vector<P> ba;
  rep(i, n) cin >> ba[i].second >> ba[i].first;

  sort(ba.rbegin(), ba.rend());
  int time = ba[0].first;
  for (auto t : ba) {
    time = min(time, t.first);
    time -= t.second;
    if (time < 0) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  int n;
  cin >> n;
  vector<P> ba(n);
  rep(i, n) cin >> ba[i].second >> ba[i].first;

  sort(ba.rbegin(), ba.rend());
  int time = ba[0].first;
  for (auto t : ba) {
    time = min(time, t.first);
    time -= t.second;
    if (time < 0) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
#define int long long
using namespace std;
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
pair<int, int> a[114514];
signed main() {
  int n;
  cin >> n;
  rep(0, i, n) {
    cin >> a[i].second;
    cin >> a[i].first;
  }
  sort(a, a + n);
  int sum = 0;
  rep(0, i, n) {
    sum += a[i].second;
    if (sum > a[i].first) {
      c("No") return 0;
    }
  }
  c("Yes")
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
#define int long long
using namespace std;
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
pair<int, int> a[214514];
signed main() {
  int n;
  cin >> n;
  rep(0, i, n) {
    cin >> a[i].second;
    cin >> a[i].first;
  }
  sort(a, a + n);
  int sum = 0;
  rep(0, i, n) {
    sum += a[i].second;
    if (sum > a[i].first) {
      c("No") return 0;
    }
  }
  c("Yes")
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

bool pairCompare(const pair<int, int> &firstElem,
                 const pair<int, int> &secondElem) {
  return firstElem.second < secondElem.second;
}

int main() {
  ll n;
  pair<ll, ll> p[100010];
  cin >> n;
  imfor(i, n) {
    ll a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p, p + n, pairCompare);
  ll t = 0;
  bool ans = true;
  imfor(i, n) {
    t += p[i].first;
    if (t > p[i].second) {
      ans = false;
      break;
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

bool pairCompare(const pair<int, int> &firstElem,
                 const pair<int, int> &secondElem) {
  return firstElem.second < secondElem.second;
}

int main() {
  ll n;
  pair<ll, ll> p[300010];
  cin >> n;
  imfor(i, n) {
    ll a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p, p + n, pairCompare);
  ll t = 0;
  bool ans = true;
  imfor(i, n) {
    t += p[i].first;
    if (t > p[i].second) {
      ans = false;
      break;
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02996 (C++)

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

int main() {
  int N;
  cin >> N;
  pair<long long, long long> pairs[100100];
  long long sum;
  sum = 0;

  for (int i = 0; i < N; i++) {
    cin >> pairs[i].second;
    cin >> pairs[i].first;
  }
  sort(pairs, pairs + N);
  for (int i = 0; i < N; i++) {
    sum += pairs[i].second;
    if (sum > pairs[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  pair<long long, long long> pairs[200200];
  long long sum;
  sum = 0;

  for (int i = 0; i < N; i++) {
    cin >> pairs[i].second;
    cin >> pairs[i].first;
  }
  sort(pairs, pairs + N);
  for (int i = 0; i < N; i++) {
    sum += pairs[i].second;
    if (sum > pairs[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <memory>
#include <set>
#include <vector>

#define ll long long

using namespace std;

const int NMAX = 100000 + 3;
int c[NMAX], d[NMAX], a[NMAX];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i] >> d[i];
    a[i] = i;
  }
  sort(a + 1, a + n + 1, [&](int a, int b) { return d[a] < d[b]; });
  cout << endl;
  // for (int i = 1; i <= n; ++i) {
  //     cout << d[a[i]] << " " << c[a[i]] << endl;
  // }
  ll time = 0;
  for (int i = 1; i <= n; ++i) {
    time += c[a[i]];
    if (time > d[a[i]]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <memory>
#include <set>
#include <vector>

#define ll long long

using namespace std;

const int NMAX = 200000 + 3;
int c[NMAX], d[NMAX], a[NMAX];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i] >> d[i];
    a[i] = i;
  }
  sort(a + 1, a + n + 1, [&](int a, int b) { return d[a] < d[b]; });
  cout << endl;
  // for (int i = 1; i <= n; ++i) {
  //     cout << d[a[i]] << " " << c[a[i]] << endl;
  // }
  ll time = 0;
  for (int i = 1; i <= n; ++i) {
    time += c[a[i]];
    if (time > d[a[i]]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02996 (C++)

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld", &x)
#define prll(x) printf("%lld ", x)
#define pri(x) printf("%d ", x)
#define si(x) scanf("%d", &x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a + 0.5);
#define NIL -1
ll N = 500005;
ll MAX = 9223372036854775807;
ll MOD = 1000000007;
long double PI = 4 * atan(1);
bool f(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.s < b.s; }
int main() {
  IOS;
  cout.precision(30);
  int n;
  cin >> n;
  ll a, b;
  vector<pair<ll, ll>> A;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    A.pb(make_pair(a, b));
  }
  sort(A.begin(), A.end(), f);
  for (int i = 0; i < n; i++) {
    int deb = i, fin = i;
    for (int j = deb + 1; j < n; j++) {
      if (A[i].s == A[j].s)
        fin++;
    }
    i = fin + 1;
    sort(A.begin() + deb, A.begin() + fin + 1);
  }
  ll s = 0;
  bool res = true;
  for (int i = 0; i < n; i++) {
    s += A[i].f;
    if (s > A[i].s) {
      res = false;
      break;
    }
  }
  if (res)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld", &x)
#define prll(x) printf("%lld ", x)
#define pri(x) printf("%d ", x)
#define si(x) scanf("%d", &x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a + 0.5);
#define NIL -1
ll N = 500005;
ll MAX = 9223372036854775807;
ll MOD = 1000000007;
long double PI = 4 * atan(1);
bool f(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.s < b.s; }
int main() {
  IOS;
  cout.precision(30);
  int n;
  cin >> n;
  ll a, b;
  vector<pair<ll, ll>> A;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    A.pb(make_pair(a, b));
  }
  sort(A.begin(), A.end(), f);
  for (int i = 0; i < n; i++) {
    int deb = i, fin = i;
    for (int j = deb + 1; j < n; j++) {
      if (A[i].s == A[j].s)
        fin++;
      else
        break;
    }
    i = fin + 1;
    sort(A.begin() + deb, A.begin() + fin + 1);
  }
  ll s = 0;
  bool res = true;
  for (int i = 0; i < n; i++) {
    s += A[i].f;
    if (s > A[i].s) {
      res = false;
      break;
    }
  }
  if (res)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02996 (C++)

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

typedef long long ll;

#define reg register
#define rep(a, b, c) for (reg int a = b, a##end = c; a <= a##end; ++a)
#define drep(a, b, c) for (reg int a = b, a##end = c; a >= a##end; --a)

char IO;
int rd() {
  int s = 0, f = 0;
  while (IO = getchar(), IO < '0' || IO > '9')
    if (IO == '-')
      f = 1;
  do
    s = (s << 1) + (s << 3) + (IO ^ '0');
  while (IO = getchar(), IO >= '0' && IO <= '9');
  return f ? -s : s;
}

const int N = 200100;

int n;

struct node {
  int x, y;
  bool operator<(const node __) const { return y < __.y; }
} a[N];

int main() {
  n = rd();
  rep(i, 1, n) a[i].x = rd(), a[i].y = rd();
  sort(a + 1, a + n + 1);
  ll now = 0;
  for (int i = 1; i <= n; i++) {
    if ((now += a[i].x) > a[i].y)
      return puts("No");
  }
  puts("Yes");
}


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

typedef long long ll;

#define reg register
#define rep(a, b, c) for (reg int a = b, a##end = c; a <= a##end; ++a)
#define drep(a, b, c) for (reg int a = b, a##end = c; a >= a##end; --a)

char IO;
int rd() {
  int s = 0, f = 0;
  while (IO = getchar(), IO < '0' || IO > '9')
    if (IO == '-')
      f = 1;
  do
    s = (s << 1) + (s << 3) + (IO ^ '0');
  while (IO = getchar(), IO >= '0' && IO <= '9');
  return f ? -s : s;
}

const int N = 200100;

int n;

struct node {
  int x, y;
  bool operator<(const node __) const { return y < __.y; }
} a[N];

int main() {
  n = rd();
  rep(i, 1, n) a[i].x = rd(), a[i].y = rd();
  sort(a + 1, a + n + 1);
  ll now = 0;
  for (int i = 1; i <= n; i++) {
    if ((now += a[i].x) > a[i].y)
      return puts("No"), 0;
  }
  puts("Yes");
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int a;
  int b;
} ab;
ab s[100100];
int com(ab t1, ab t2) { return t1.b < t2.b; }
int main() {
  int n, flag = 1, ti = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%d%d", &s[i].a, &s[i].b);
  sort(s, s + n, com);
  for (int i = 0; i < n; i++) {
    ti += s[i].a;
    if (ti > s[i].b) {
      flag = 0;
      break;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int a;
  int b;
} ab;
ab s[200100];
int com(ab t1, ab t2) { return t1.b < t2.b; }
int main() {
  int n, flag = 1, ti = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%d%d", &s[i].a, &s[i].b);
  sort(s, s + n, com);
  for (int i = 0; i < n; i++) {
    ti += s[i].a;
    if (ti > s[i].b) {
      flag = 0;
      break;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02996 (C++)

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

int main() {
  int N;
  cin >> N;
  int A[100100], B[100100];
  P C[100100];

  bool flag = true;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (b < a)
      flag = false;
    C[i] = P(b, a);
  }
  //
  sort(C, C + N);
  ll now = 0;

  for (int i = 0; i < N; i++) {
    ll x = C[i].first;
    ll y = C[i].second;
    if (now + y > x) {
      flag = false;
    } else {
      now += y;
    }
  }

  if (!flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int N;
  cin >> N;
  ;
  P C[200100];

  bool flag = true;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (b < a)
      flag = false;
    C[i] = P(b, a);
  }
  //
  sort(C, C + N);
  ll now = 0;

  for (int i = 0; i < N; i++) {
    ll x = C[i].first;
    ll y = C[i].second;
    if (now + y > x) {
      flag = false;
    } else {
      now += y;
    }
  }

  if (!flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

#define ll long long
const ll N = 2 * 1e5;

ll n, m;
struct node {
  ll a, b;
} f[N];

bool cmp(node a, node b) { return a.b < b.b; }

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%lld%lld", &f[i].a, &f[i].b);
  sort(f + 1, f + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    m += f[i].a;
    if (m > f[i].b) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

#define ll long long
const int N = 3 * 1e5;

ll n, m;
struct node {
  ll a, b;
} f[N];

bool cmp(node a, node b) { return a.b < b.b; }

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%lld%lld", &f[i].a, &f[i].b);
  sort(f + 1, f + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    m += f[i].a;
    if (m > f[i].b) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
typedef long long int ll;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;

int N;
int sum = 0;
bool judge = true;

int main(void) {
  pair<int, int> a[100001];
  cin >> N;
  rep(i, 0, N) cin >> a[i].second >> a[i].first;
  sort(a, a + N);
  rep(i, 0, N) {
    sum += a[i].second;
    if (sum > a[i].first) {
      judge = false;
      break;
    }
  }

  if (judge == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
typedef long long int ll;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;

int N;
int sum = 0;
bool judge = true;

int main(void) {
  pair<int, int> a[200001];
  cin >> N;
  rep(i, 0, N) cin >> a[i].second >> a[i].first;
  sort(a, a + N);
  rep(i, 0, N) {
    sum += a[i].second;
    if (sum > a[i].first) {
      judge = false;
      break;
    }
  }

  if (judge == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
void printArr(int *a, int len) {
  for (int i = 0; i < len; i++) {
    if (i)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

//--global--//

struct MyTask {
  ll a, b;
  MyTask() {}
  MyTask(ll a0, ll b0) : a(a0), b(b0) {}
  bool operator<(const MyTask &rhs) const {
    if (b < rhs.b) {
      return true;
    }
    return false;
  }
};

//----------//

int main(int argc, const char *argv[]) {
  // 提出時、消す----//
  //--------------//

  ll n;
  cin >> n;
  MyTask Tasks[MAX];
  rep(i, n) {
    ll a;
    ll b;
    cin >> a;
    cin >> b;
    Tasks[i] = MyTask(a, b);
  }
  sort(Tasks, Tasks + n,
       [](const MyTask &x, const MyTask &y) { return x.a < y.a; });
  sort(Tasks, Tasks + n);
  ll now = 0;
  rep(i, n) {
    now += Tasks[i].a;
    if (now > Tasks[i].b) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
void printArr(int *a, int len) {
  for (int i = 0; i < len; i++) {
    if (i)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 200001;
static const ll MOD = 1000000007;

//--global--//

struct MyTask {
  ll a, b;
  MyTask() {}
  MyTask(ll a0, ll b0) : a(a0), b(b0) {}
  bool operator<(const MyTask &rhs) const {
    if (b < rhs.b) {
      return true;
    }
    return false;
  }
};

//----------//

int main(int argc, const char *argv[]) {
  // 提出時、消す----//
  //--------------//

  ll n;
  cin >> n;
  MyTask Tasks[MAX];
  rep(i, n) {
    ll a;
    ll b;
    cin >> a;
    cin >> b;
    Tasks[i] = MyTask(a, b);
  }
  sort(Tasks, Tasks + n,
       [](const MyTask &x, const MyTask &y) { return x.a < y.a; });
  sort(Tasks, Tasks + n);
  ll now = 0;
  rep(i, n) {
    now += Tasks[i].a;
    if (now > Tasks[i].b) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;

//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

typedef struct {
  ll time, dead;
} work;

int workcmp(const void *a, const void *b) {
  if ((*(work *)a).dead < (*(work *)b).dead)
    return -1;
  else if ((*(work *)a).dead == (*(work *)b).dead)
    return 0;
  else
    return 1;
}

int main(void) {
  int N;
  work W[100010];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> W[i].time >> W[i].dead;
  qsort(W, N, sizeof(work), workcmp);
  ll C = 0;
  for (int i = 0; i < N; i++) {
    C += W[i].time;
    if (W[i].dead < C) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;

//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

typedef struct {
  ll time, dead;
} work;

int workcmp(const void *a, const void *b) {
  if ((*(work *)a).dead < (*(work *)b).dead)
    return -1;
  else if ((*(work *)a).dead == (*(work *)b).dead)
    return 0;
  else
    return 1;
}

int main(void) {
  int N;
  work W[200010];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> W[i].time >> W[i].dead;
  qsort(W, N, sizeof(work), workcmp);
  ll C = 0;
  for (int i = 0; i < N; i++) {
    C += W[i].time;
    if (W[i].dead < C) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

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

using namespace std;

struct Task {
  long A, B;
};

bool cmp(const Task &t1, const Task &t2) {
  if (t1.B < t2.B) {
    return true;
  } else if (t1.B > t2.B) {
    return false;
  } else {
    return t1.A >= t2.A;
  }
}

int main() {
  int N;
  cin >> N;
  vector<Task> tsk(N);
  long a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    tsk[i] = Task{a, b};
  }
  sort(tsk.begin(), tsk.end(), cmp);

  long time = 0;
  for (int i = 0; i < N; i++) {
    time += tsk[i].A;
    if (time > tsk[i].B) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

using namespace std;

struct Task {
  long A, B;
};

bool cmp(const Task &t1, const Task &t2) {
  if (t1.B < t2.B) {
    return true;
  } else if (t1.B > t2.B) {
    return false;
  } else {
    return t1.A > t2.A;
  }
}

int main() {
  int N;
  cin >> N;
  vector<Task> tsk(N);
  long a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    tsk[i] = Task{a, b};
  }
  sort(tsk.begin(), tsk.end(), cmp);

  long time = 0;
  for (int i = 0; i < N; i++) {
    time += tsk[i].A;
    if (time > tsk[i].B) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p02996 (C++)

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

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

  int N;
  cin >> N;
  vector<P> lis;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    lis.push_back(P(b, a));
  }

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

  ll pre = 0;
  for (int i = 0; i <= N; i++) {
    if (pre + lis.at(i).second > lis.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
    pre += lis.at(i).second;
  }

  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

  int N;
  cin >> N;
  vector<P> lis;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    lis.push_back(P(b, a));
  }

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

  ll pre = 0;
  for (int i = 0; i < N; i++) {
    if (pre + lis.at(i).second > lis.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
    pre += lis.at(i).second;
  }

  cout << "Yes" << endl;
  return 0;
}