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

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

using namespace std;
using ll = long long;

const int N = 55, M = 21;

int n;
vector<pair<int, int>> g[N];
int m;
int pt[M];

bool prec(int st, int en, int id, int par = -1) {
  if (st == en)
    return true;
  for (auto p : g[st])
    if (p.first != par) {
      if (prec(p.first, en, id, st)) {
        pt[p.second] |= 1 << id;
        return true;
      }
    }
  return false;
}

ll dp[N][1 << M];

ll f(int i, int mask) {
  if (i == n - 1)
    return mask == (1 << m) - 1;
  ll &ans = dp[i][mask];
  if (~ans)
    return ans;
  return ans = f(i + 1, mask) + f(i + 1, mask | pt[i]);
}

int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }

  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    assert(prec(u, v, i));
  }

  printf("%lld\n", f(0, 0));
}


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

using namespace std;
using ll = long long;

const int N = 55, M = 21;

int n;
vector<pair<int, int>> g[N];
int m;
int pt[N];

bool prec(int st, int en, int id, int par = -1) {
  if (st == en)
    return true;
  for (auto p : g[st])
    if (p.first != par) {
      if (prec(p.first, en, id, st)) {
        pt[p.second] |= 1 << id;
        return true;
      }
    }
  return false;
}

ll dp[N][1 << M];

ll f(int i, int mask) {
  if (i == n - 1)
    return mask == (1 << m) - 1;
  ll &ans = dp[i][mask];
  if (~ans)
    return ans;
  return ans = f(i + 1, mask) + f(i + 1, mask | pt[i]);
}

int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }

  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    assert(prec(u, v, i));
  }

  printf("%lld\n", f(0, 0));
}
Problem p02794 (C++)

Buggy submission (status: Runtime Error):
#define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v[57];
long long dp[1 << 20];
int x[57];
bool dfs(int a, int b, int c, int d) {
  if (a == c)
    return 1;
  for (auto it : v[a]) {
    if (it.first != b && dfs(it.first, a, c, d)) {
      x[it.second] ^= 1 << d;
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].emplace_back(b, i);
    v[b].emplace_back(a, i);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    dfs(a, 0, b, i);
  }
  dp[0] = 1;
  for (int i = 1; i < n; ++i)
    for (int j = (1 << m) - 1; j >= 0; --j)
      dp[j | x[i]] += dp[j];
  cout << dp[(1 << m) - 1];
  return 0;
}


Fixed submission:
#define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v[57];
long long dp[1 << 20];
int x[57];
bool dfs(int a, int b, int c, int d) {
  if (a == c)
    return 1;
  for (auto it : v[a]) {
    if (it.first != b && dfs(it.first, a, c, d)) {
      x[it.second] ^= 1 << d;
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].emplace_back(b, i);
    v[b].emplace_back(a, i);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    dfs(a, 0, b, i);
  }
  dp[0] = 1;
  for (int i = 1; i < n; ++i)
    for (int j = (1 << m) - 1; j >= 0; --j)
      dp[j | x[i]] += dp[j];
  cout << dp[(1 << m) - 1];
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

void checkStream() {
#ifndef _DEBUFG
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
}

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

  int r{}, c{}, n{};
  cin >> r >> c >> n;

  int step1{}, step2{};
  int ttl{};
  for (int i{}; i < r && ttl < n; ++i) {
    ttl += c;
    ++step1;
  }

  ttl = 0;
  for (int i{}; i < c && ttl < n; ++i) {
    ttl += r;
    ++step2;
  }
  cout << min(step1, step2) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

void checkStream() {
#ifndef _DEBUFG
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
}

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

  int r{}, c{}, n{};
  cin >> r >> c >> n;

  int step1{}, step2{};
  int ttl{};
  for (int i{}; i < r && ttl < n; ++i) {
    ttl += c;
    ++step1;
  }

  ttl = 0;
  for (int i{}; i < c && ttl < n; ++i) {
    ttl += r;
    ++step2;
  }
  cout << min(step1, step2) << endl;
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int, int>
#define ff first
#define ss second
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
// #include "debug.cpp"

int32_t main() {
  boost;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

  int a, b, n;
  cin >> a >> b >> n;
  if (a < b)
    swap(a, b);
  int ans = 0;
  while (ans * a < n)
    ans++;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int, int>
#define ff first
#define ss second
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
// #include "debug.cpp"

int32_t main() {
  boost;

  int a, b, n;
  cin >> a >> b >> n;
  if (a < b)
    swap(a, b);
  int ans = 0;
  while (ans * a < n)
    ans++;
  cout << ans << endl;
}
Problem p02795 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int h, w, k, omen;
  scanf("%d %d %d", &h, &w, &k);
  if (h > w)
    omen = h;
  int count = 1;
  for (int i = omen; i < k; i += omen) {
    count++;
  }
  printf("%d\n", count);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int h, w, k, omen;
  scanf("%d %d %d", &h, &w, &k);
  if (h > w)
    omen = h;
  else
    omen = w;
  int count = 1;
  for (int i = omen; i < k; i += omen) {
    count++;
  }
  printf("%d\n", count);
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e2 + 15;
int dx[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
int dy[8] = {0, -1, 1, 0, 1, -1, -1, 1};

int main() {
  fast();
  ll a, b, c;
  cin >> a >> b >> c;
  cout << ceil(double(c) / max(a, b)) << endl;
  return 0;
}

Fixed submission:
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
  /*#ifndef ONLINE_JUDGE
          freopen("output.txt", "w", stdout);
          freopen("input.txt", "r", stdin);
  #endif
  #ifdef ONLINE_JUDGE
          /*freopen("output.txt", "w", stdout);
          freopen("pyramid.in", "r", stdin);
  #endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e2 + 15;
int dx[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
int dy[8] = {0, -1, 1, 0, 1, -1, -1, 1};

int main() {
  fast();
  ll a, b, c;
  cin >> a >> b >> c;
  cout << ceil(double(c) / max(a, b)) << endl;
  return 0;
}
Problem p02795 (C++)

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

using namespace std;

int m, h, w, n, ans = 0;

int main() {
  cin >> h >> w >> n;
  if (h < w)
    swap(h, w);
  if (n <= h) {
    cout << "1";
    return 0;
  } else {
    ans += n / h;
    n %= h;
    if (n % (h - ans) == 0)
      m = n / (h - ans);
    else
      m = n / (h - ans) + 1;
  }
  cout << ans + m;
  return 0;
}

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

using namespace std;

int m, h, w, n, ans = 0;

int main() {
  cin >> h >> w >> n;
  if (h < w)
    swap(h, w);
  if (n <= h) {
    cout << "1";
    return 0;
  } else {
    ans += n / h;
    n %= h;
    if (n == 0) {
      cout << ans;
      return 0;
    }
    if (n % (h - ans) == 0)
      m = n / (h - ans);
    else
      m = n / (h - ans) + 1;
  }
  cout << ans + m;
  return 0;
}
Problem p02795 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll int h, w, n, r, s, res = 0;
  cin >> h >> w >> n;
  r = max(h, w);
  s = min(h, w);
  while (n > 0) {
    n -= r;
    res++;
  }
  cout << res << endl;
}

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

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

  ll int h, w, n, r, s, res = 0;
  cin >> h >> w >> n;
  r = max(h, w);
  s = min(h, w);
  while (n > 0) {
    n -= r;
    res++;
  }
  cout << res << endl;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, N;
  cin >> H >> W >> N;
  cout << N / max(H, W) + N % (N / max(H, W) * max(H, W)) / min(H, W);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, N;
  cin >> H >> W >> N;
  if (N % (max(H, W)) == 0) {
    cout << N / max(H, W);
  } else {
    cout << N / (max(H, W)) + 1;
  }
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout << "\n";
#define all(x) (x).begin(), (x).end()
#define tr(c, i) for (auto i : c)
#define pii pair<int, int>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define pq                                                                     \
  priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> \
      p; // container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x, y) cout << x << " " << y
using namespace std;

const ll MAX = 1000 * 1000;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 301;
const int INF = INT_MAX;
const int M = 200005;
int main() {

  ll h, w, n;
  cin >> h >> w >> n;

  if (h < w)
    swap(h, w);

  ll res = n / h;
  n -= res * h;
  w -= res;
  res += n / w;
  cout << res;

  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout << "\n";
#define all(x) (x).begin(), (x).end()
#define tr(c, i) for (auto i : c)
#define pii pair<int, int>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define pq                                                                     \
  priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> \
      p; // container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x, y) cout << x << " " << y
using namespace std;

const ll MAX = 1000 * 1000;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 301;
const int INF = INT_MAX;
const int M = 200005;
int main() {

  ll h, w, n;
  cin >> h >> w >> n;
  cout << min((n + h - 1) / h, (n + w - 1) / w);

  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int h, w, n;
  cin >> h;
  cin >> w;
  cin >> n;

  int a = max(h, w);
  int count = 0;

  while (1) {
    if (n >= a) {
      n -= a;
      count++;
    }

    if (n <= 0) {
      break;
    }
  }

  cout << count << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int h, w, n;
  cin >> h;
  cin >> w;
  cin >> n;

  int a = max(h, w);
  int count = 0;

  while (1) {
    n -= a;
    count++;
    if (n <= 0) {
      break;
    }
  }

  cout << count << endl;
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

int main() {
  int h;
  int w;
  int n;
  int paintNum = 0;
  std::cin >> h >> w >> n;
  while (n > 0) {
    if (w > h) {
      paintNum++;
      n -= w;
    } else if (h > w) {
      paintNum++;
      n -= h;
    }
  }
  std::cout << paintNum << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  int h;
  int w;
  int n;
  int paintNum = 0;
  std::cin >> h >> w >> n;
  while (n > 0) {
    if (w > h) {
      paintNum++;
      n -= w;
    } else {
      paintNum++;
      n -= h;
    }
  }
  std::cout << paintNum << std::endl;
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int N, H, W, B;
  cin >> H;
  cin >> W;
  cin >> N;

  B = 0;
  int i;
  for (i = 0; B < N; i++) {
    if (W > H) {
      B += W;
    }
    if (H > W) {
      B += H;
    }
  }
  cout << i << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int N, H, W, B;
  cin >> H;
  cin >> W;
  cin >> N;

  B = 0;
  int i;
  for (i = 0; B < N; i++) {
    if (W > H) {
      B += W;
    } else {
      B += H;
    }
  }
  cout << i << endl;
  return 0;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int a = max(h, w);
  int k = n / a;
  if (n % k != 0)
    k++;
  cout << k << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int a = max(h, w);
  if (n >= a) {
    int k = n / a;
    if (n % a != 0)
      k++;
    cout << k << endl;
  } else
    cout << 1 << endl;
}
Problem p02795 (C++)

Buggy submission (status: Runtime Error):
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll po(ll base, ll powerRaised) {
  if (powerRaised != 0)
    return (base * po(base, powerRaised - 1));
  else
    return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif //*/
  long double h, w, n;
  cin >> h >> w >> n;
  cout << ceil(n / max(h, w));
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Fixed submission:
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll po(ll base, ll powerRaised) {
  if (powerRaised != 0)
    return (base * po(base, powerRaised - 1));
  else
    return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif //*/
  long double h, w, n;
  cin >> h >> w >> n;
  cout << ceil(n / max(h, w));
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
Problem p02796 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)])
T = []
for i in range(N):
    T.append([R[i][0] + R[i][1], R[i][0] - R[i][1]])
T.sort()
while len(T) - 1 > 0:
    t = T.pop(0)
    i = 1
    while len(T) and t[0] > T[0][1]:
        N -= 1
        i += 1
        T.pop(0)
print(N)


Fixed submission:
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
LR = [[x[0] - x[1], x[0] + x[1]] for x in X]
LR.sort(key=lambda x: x[1])

A = 1
right = LR[0][1]
for i in range(1, N):
    if right <= LR[i][0]:
        A += 1
        right = LR[i][1]
print(A)
Problem p02796 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
(n,), *r = [[*map(int, i.split())] for i in open(0)]
s = sorted([[x + l, x - l] for x, l in r])
c = 0
p = 0
while s:
    c += 1
    p = s[0][0]
    s = [i for i in s if i[1] >= p]
print(c)


Fixed submission:
#!/usr/bin/env python3
(n,), *r = [[*map(int, i.split())] for i in open(0)]
s = sorted([[x + l, x - l] for x, l in r])
c = 1
p = s[0][0]
for i in s[1:]:
    if i[1] >= p:
        c += 1
        p = i[0]
print(c)
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
/**
 *   author  : The San Cao (caothesan@gmail.com)
 *   created : 2020.02.08 10:32:46 +07
 */

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

const int maxn = 1e5 + 10;

int n;
int t[maxn];
vector<pair<int, int>> robots;

void update(int x, int v) {
  for (; x < maxn; x += x & -x)
    t[x] = max(t[x], v);
}

int get(int x) {
  int res = 0;
  for (; x > 0; x -= x & -x)
    res = max(res, t[x]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  vector<int> c;
  for (int i = 0; i < n; ++i) {
    int x, l;
    cin >> x >> l;
    robots.emplace_back(x + l, x - l);
    c.push_back(x + l);
    c.push_back(x - l);
  }
  sort(c.begin(), c.end());
  for (auto &it : robots) {
    it.first = lower_bound(c.begin(), c.end(), it.first) - c.begin() + 1;
    it.second = lower_bound(c.begin(), c.end(), it.second) - c.begin() + 1;
  }
  sort(robots.begin(), robots.end());
  int answer = 0;
  for (auto it : robots) {
    int cur = get(it.second);
    answer = max(answer, cur + 1);
    update(it.first, cur + 1);
  }
  cout << answer << "\n";
  return 0;
}


Fixed submission:
/**
 *   author  : The San Cao (caothesan@gmail.com)
 *   created : 2020.02.08 10:32:46 +07
 */

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

const int maxn = 2e5 + 10;

int n;
int t[maxn];
vector<pair<int, int>> robots;

void update(int x, int v) {
  for (; x < maxn; x += x & -x)
    t[x] = max(t[x], v);
}

int get(int x) {
  int res = 0;
  for (; x > 0; x -= x & -x)
    res = max(res, t[x]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  vector<int> c;
  for (int i = 0; i < n; ++i) {
    int x, l;
    cin >> x >> l;
    robots.emplace_back(x + l, x - l);
    c.push_back(x + l);
    c.push_back(x - l);
  }
  sort(c.begin(), c.end());
  for (auto &it : robots) {
    it.first = lower_bound(c.begin(), c.end(), it.first) - c.begin() + 1;
    it.second = lower_bound(c.begin(), c.end(), it.second) - c.begin() + 1;
  }
  sort(robots.begin(), robots.end());
  int answer = 0;
  for (auto it : robots) {
    int cur = get(it.second);
    answer = max(answer, cur + 1);
    update(it.first, cur + 1);
  }
  cout << answer << "\n";
  return 0;
}
Problem p02796 (C++)

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

using namespace std;
typedef long long ll;
struct player {
  ll x;
  ll b;
};

const int MAXN = 1100;
player A[MAXN];

bool player_compare(player p1, player p2) {
  return (p1.x + p1.b) < (p2.x + p2.b);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, b;
    cin >> x >> b;
    player p;
    p.x = x;
    p.b = b;
    A[i] = p;
  }
  sort(A, A + n, player_compare);
  int total = 1;
  int i = 1;
  int right = A[0].x + A[0].b;
  while (i < n) {
    if (A[i].x - A[i].b >= right) {
      total++;
      right = A[i].x + A[i].b;
    }
    i++;
  }
  cout << total << "\n";
}


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

using namespace std;
typedef long long ll;
struct player {
  ll x;
  ll b;
};

const int MAXN = 100100;
player A[MAXN];

bool player_compare(player p1, player p2) {
  return (p1.x + p1.b) < (p2.x + p2.b);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, b;
    cin >> x >> b;
    player p;
    p.x = x;
    p.b = b;
    A[i] = p;
  }
  sort(A, A + n, player_compare);
  int total = 1;
  int i = 1;
  int right = A[0].x + A[0].b;
  while (i < n) {
    if (A[i].x - A[i].b >= right) {
      total++;
      right = A[i].x + A[i].b;
    }
    i++;
  }
  cout << total << "\n";
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
typedef pair<ll, ll> P;
const ll INF = 1e18;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll int n, i;
  cin >> n;
  ll int x[n], l[n];
  for (i = 0; i < n; i++) {
    cin >> x[i] >> l[i];
  }

  vector<P> v;
  for (i = 0; i < n; i++) {
    v.push_back(P(x[i] + l[i], x[i] - l[i]));
  }
  sort(v.begin(), v.end());

  ll int ans = 0;
  ll int at = -INF;
  for (i = 0; i < n; i++) {
    ll int left = v[i].second;
    ll int right = v[i].first;
    if (left >= at) {
      ans++;
      at = right;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
typedef pair<ll, ll> P;
const ll INF = 1e18;

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

  ll int n, i;
  cin >> n;
  ll int x[n], l[n];
  for (i = 0; i < n; i++) {
    cin >> x[i] >> l[i];
  }

  vector<P> v;
  for (i = 0; i < n; i++) {
    v.push_back(P(x[i] + l[i], x[i] - l[i]));
  }
  sort(v.begin(), v.end());

  ll int ans = 0;
  ll int at = -INF;
  for (i = 0; i < n; i++) {
    ll int left = v[i].second;
    ll int right = v[i].first;
    if (left >= at) {
      ans++;
      at = right;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
struct Meet {
  int beg;
  int end;
  int num;
} meet[1000];

class setMeet {
public:
  void init();
  void solve();

private:
  int n, ans;
};
void setMeet::init() {
  int s, e;
  cin >> n;
  int i;
  for (i = 0; i < n; ++i) {
    cin >> s >> e;
    int min, max;
    max = s + e;
    min = s - e;
    meet[i].beg = min;
    meet[i].end = max;
    meet[i].num = i + 1;
  }
}

bool cmp(Meet x, Meet y) {
  if (x.end == y.end)
    return x.beg > y.beg;
  return x.end < y.end;
}

void setMeet::solve() {
  sort(meet, meet + n, cmp);
  int i;
  ans = 1;
  int last = meet[0].end;
  for (i = 1; i < n; ++i) {
    if (meet[i].beg >= last) {
      ans++;
      last = meet[i].end;
    }
  }
  cout << ans << endl;
}
int main() {
  setMeet sm;
  sm.init();
  sm.solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
struct Meet {
  int beg;
  int end;
  int num;
} meet[100000];

class setMeet {
public:
  void init();
  void solve();

private:
  int n, ans;
};
void setMeet::init() {
  int s, e;
  cin >> n;
  int i;
  for (i = 0; i < n; ++i) {
    cin >> s >> e;
    int min, max;
    max = s + e;
    min = s - e;
    meet[i].beg = min;
    meet[i].end = max;
    meet[i].num = i + 1;
  }
}

bool cmp(Meet x, Meet y) {
  if (x.end == y.end)
    return x.beg > y.beg;
  return x.end < y.end;
}

void setMeet::solve() {
  sort(meet, meet + n, cmp);
  int i;
  ans = 1;
  int last = meet[0].end;
  for (i = 1; i < n; ++i) {
    if (meet[i].beg >= last) {
      ans++;
      last = meet[i].end;
    }
  }
  cout << ans << endl;
}
int main() {
  setMeet sm;
  sm.init();
  sm.solve();
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct Sect {
  int L, R;
  int x, len;
  int size;
};
Sect sects[100010];
int n;

bool compare(const Sect &a, const Sect &b) {
  if (a.R == b.R)
    return a.L < b.L;
  else
    return a.R < b.R;
}

int calcStart(int startP) {
  int count = 1;
  int nextR = sects[startP].R;
  for (int i = startP + 1; i < n; i++) {
    if (nextR <= sects[i].L) {
      count++;
      nextR = sects[i].R;
    }
  }

  return count;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &(sects[i].x), &(sects[i].len));
    sects[i].L = sects[i].x - sects[i].len;
    sects[i].R = sects[i].x + sects[i].len;
    sects[i].size = sects[i].R - sects[i].L + 1;
  }

  sort(sects, sects + n, compare);

  int maxNum = 0;
  for (int i = 0; i < n; i++) {
    int curNum = calcStart(i);
    if (curNum > maxNum)
      maxNum = curNum;
  }

  printf("%d\n", maxNum);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct Sect {
  int L, R;
  int x, len;
  int size;
};
Sect sects[100010];
int n;

bool compare(const Sect &a, const Sect &b) {
  if (a.R == b.R)
    return a.L < b.L;
  else
    return a.R < b.R;
}

int calcStart(int startP) {
  int count = 1;
  int nextR = sects[startP].R;
  for (int i = startP + 1; i < n; i++) {
    if (nextR <= sects[i].L) {
      count++;
      nextR = sects[i].R;
    }
  }

  return count;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &(sects[i].x), &(sects[i].len));
    sects[i].L = sects[i].x - sects[i].len;
    sects[i].R = sects[i].x + sects[i].len;
    sects[i].size = sects[i].R - sects[i].L + 1;
  }

  sort(sects, sects + n, compare);

  int maxNum = 0;
  //	for (int i = 0 ; i < n ; i++) {
  int curNum = calcStart(0);
  if (curNum > maxNum)
    maxNum = curNum;
  //	}

  printf("%d\n", maxNum);

  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
struct node {
  int s;
  int f;
} a[1100];
int cmp(const node &x, const node &y) { return x.f < y.f; }
int n;
int main() {
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    int t = x, tt = y;
    x = t - tt;
    y = t + tt;
    a[i].s = x;
    a[i].f = y;
  }
  sort(a + 1, a + n + 1, cmp);
  int tot = 1;
  int now = a[1].f;
  for (int i = 2; i <= n; i++) {
    if (a[i].s >= now) {
      tot++;
      now = a[i].f;
    }
  }
  printf("%d", tot);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
struct node {
  int s;
  int f;
} a[110000];
int cmp(const node &x, const node &y) { return x.f < y.f; }
int n;
int main() {
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    int t = x, tt = y;
    x = t - tt;
    y = t + tt;
    a[i].s = x;
    a[i].f = y;
  }
  sort(a + 1, a + n + 1, cmp);
  int tot = 1;
  int now = a[1].f;
  for (int i = 2; i <= n; i++) {
    if (a[i].s >= now) {
      tot++;
      now = a[i].f;
    }
  }
  printf("%d", tot);
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int n, t = 0, ans = 0;
const int MAX_N = 10000;
pair<int, int> robo[MAX_N];

int main() {
  cin >> n;
  // vector<robop> robo(n);
  int p1, p2;
  for (int i = 0; i < n; i++) {
    cin >> p1;
    cin >> p2;
    robo[i].first = p1 + p2;
    robo[i].second = p1 - p2;
  }

  sort(robo, robo + n);
  // cout << "-" << endl;
  for (int i = 0; i < n; i++) {
    int start = robo[i].second;
    // cout << start << " " << t << " ";
    if (start < 0)
      start = 0;
    // cout << start << " " << t <<endl;
    if (t <= start && start != 0) {
      t = robo[i].first;
      ans++;
    } else if (start == 0 && ans == 0) {
      t = robo[i].first;
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int n, t = 0, ans = 0;
const int MAX_N = 100000;
pair<int, int> robo[MAX_N];

int main() {
  cin >> n;
  // vector<robop> robo(n);
  int p1, p2;
  for (int i = 0; i < n; i++) {
    cin >> p1;
    cin >> p2;
    robo[i].first = p1 + p2;
    robo[i].second = p1 - p2;
  }

  sort(robo, robo + n);
  // cout << "-" << endl;
  for (int i = 0; i < n; i++) {
    int start = robo[i].second;
    // cout << start << " " << t << " ";
    if (start < 0)
      start = 0;
    // cout << start << " " << t <<endl;
    if (t <= start && start != 0) {
      t = robo[i].first;
      ans++;
    } else if (start == 0 && ans == 0) {
      t = robo[i].first;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02796 (C++)

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

int qmax(int a, int b) { return (a > b) ? a : b; }

int n;
int l[100100], r[100100];
vector<int> robot[100100];
int dp[200200];
map<int, int> mp;
set<int> s;

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int x, L;
    scanf("%d %d", &x, &L);
    l[i] = x - L, r[i] = x + L;
    s.insert(l[i]), s.insert(r[i]);
  }
  int cnt = 0;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++, cnt++) {
    mp[*it] = cnt;
  }
  rep(i, n) {
    l[i] = mp[l[i]];
    r[i] = mp[r[i]];
    robot[r[i]].push_back(i);
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i < cnt; i++) {
    dp[i] = dp[i - 1];
    rep(j, robot[i].size()) { dp[i] = qmax(dp[i], dp[l[robot[i][j]]] + 1); }
  }
  cout << dp[cnt - 1] << endl;
  return 0;
}

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

int qmax(int a, int b) { return (a > b) ? a : b; }

int n;
int l[100100], r[100100];
vector<int> robot[200200];
int dp[200200];
map<int, int> mp;
set<int> s;

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int x, L;
    scanf("%d %d", &x, &L);
    l[i] = x - L, r[i] = x + L;
    s.insert(l[i]), s.insert(r[i]);
  }
  int cnt = 0;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++, cnt++) {
    mp[*it] = cnt;
  }
  rep(i, n) {
    l[i] = mp[l[i]];
    r[i] = mp[r[i]];
    robot[r[i]].push_back(i);
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i < cnt; i++) {
    dp[i] = dp[i - 1];
    rep(j, robot[i].size()) { dp[i] = qmax(dp[i], dp[l[robot[i][j]]] + 1); }
  }
  cout << dp[cnt - 1] << endl;
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int n = 0;
  bool b = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      b = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    n = (n << 3) + (n << 1) + (c ^ 48), c = getchar();
  return b ? n : -n;
}
struct dalao {
  int left;
  int right;
} a[50100];
bool juruo(dalao x, dalao y) { return x.right < y.right; }
int main() {
  int n, s = 1, d;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t1 = read(), t2 = read();
    a[i].left = t1 - t2, a[i].right = t1 + t2;
  }
  sort(a + 1, a + n + 1, juruo);
  d = a[1].right;
  for (int i = 2; i <= n; i++) {
    if (a[i].left >= d) {
      d = a[i].right;
      s++;
    }
  }
  cout << s;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int n = 0;
  bool b = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      b = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    n = (n << 3) + (n << 1) + (c ^ 48), c = getchar();
  return b ? n : -n;
}
struct dalao {
  int left;
  int right;
} a[100100];
bool juruo(dalao x, dalao y) { return x.right < y.right; }
int main() {
  int n, s = 1, d;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t1 = read(), t2 = read();
    a[i].left = t1 - t2, a[i].right = t1 + t2;
  }
  sort(a + 1, a + n + 1, juruo);
  d = a[1].right;
  for (int i = 2; i <= n; i++) {
    if (a[i].left >= d) {
      d = a[i].right;
      s++;
    }
  }
  cout << s;
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int)x.size()
#define pb push_back
#define ll long long
#define ld double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define DOW(i, n) for (int i = n - 1; 0 <= i; --i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);

using namespace std;

const int nax = 1e5 + 111;

int n;
pair<int, int> t[nax];
vector<int> vec;
int pref[nax];

map<int, int> mapa;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &t[i].fi, &t[i].se);
    mapa[t[i].fi] = t[i].se;
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i <= n; ++i) {
    vec.pb(t[i].fi);
    vec.pb(t[i].fi + t[i].se);
    if (t[i].fi - t[i].se >= 0)
      vec.pb(t[i].fi - t[i].se);
  }

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  for (int i = 0; i < ss(vec); ++i) {
    if (i)
      pref[i] = max(pref[i], pref[i - 1]);
    if (mapa.find(vec[i]) == mapa.end())
      continue;
    int x = vec[i];
    int l = mapa[x];
    int prawo = (int)(lower_bound(vec.begin(), vec.end(), x + l) - vec.begin());
    int lewo =
        (int)(upper_bound(vec.begin(), vec.end(), x - l) - vec.begin()) - 1;
    int ja = 1;
    if (lewo >= 0)
      ja += pref[lewo];
    //	cout << x << ""  << ja << " " << lewo << " " << prawo << " " << i <<
    //endl;
    pref[prawo] = max(pref[prawo], ja);
  }
  printf("%d", pref[ss(vec) - 1]);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int)x.size()
#define pb push_back
#define ll long long
#define ld double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define DOW(i, n) for (int i = n - 1; 0 <= i; --i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);

using namespace std;

const int nax = 4e5 + 111;

int n;
pair<int, int> t[nax];
vector<int> vec;
int pref[nax];

map<int, int> mapa;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &t[i].fi, &t[i].se);
    mapa[t[i].fi] = t[i].se;
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i <= n; ++i) {
    vec.pb(t[i].fi);
    vec.pb(t[i].fi + t[i].se);
    if (t[i].fi - t[i].se >= 0)
      vec.pb(t[i].fi - t[i].se);
  }

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  for (int i = 0; i < ss(vec); ++i) {
    if (i)
      pref[i] = max(pref[i], pref[i - 1]);
    if (mapa.find(vec[i]) == mapa.end())
      continue;
    int x = vec[i];
    int l = mapa[x];
    int prawo = (int)(lower_bound(vec.begin(), vec.end(), x + l) - vec.begin());
    int lewo =
        (int)(upper_bound(vec.begin(), vec.end(), x - l) - vec.begin()) - 1;
    int ja = 1;
    if (lewo >= 0)
      ja += pref[lewo];
    //	cout << x << ""  << ja << " " << lewo << " " << prawo << " " << i <<
    //endl;
    pref[prawo] = max(pref[prawo], ja);
  }
  printf("%d", pref[ss(vec) - 1]);

  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
struct line {
  int l, r;

} a[101];
bool operator<(const line &a, const line &b) { return a.r < b.r; }
int main() {
  int n, tot = 1;
  cin >> n;
  for (int i = 1, x, L; i <= n; i++) {
    cin >> x >> L;
    a[i].l = x - L;
    a[i].r = x + L;
  }
  sort(a + 1, a + n + 1);
  int end = a[1].r;
  for (int i = 2; i <= n; i++) {
    if (a[i].l >= end) {
      tot++;
      end = a[i].r;
    }
  }
  cout << tot << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
struct line {
  int l, r;

} a[100010];
bool operator<(const line &a, const line &b) { return a.r < b.r; }
int main() {
  int n, tot = 1;
  cin >> n;
  for (int i = 1, x, L; i <= n; i++) {
    cin >> x >> L;
    a[i].l = x - L;
    a[i].r = x + L;
  }
  sort(a + 1, a + n + 1);
  int end = a[1].r;
  for (int i = 2; i <= n; i++) {
    if (a[i].l >= end) {
      tot++;
      end = a[i].r;
    }
  }
  cout << tot << endl;
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int s, e;
} list[40010];
bool cmp(node x, node y) { return x.e < y.e; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int x, l;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &x, &l);
      list[i].s = x - l;
      list[i].e = x + l;
    }
    /* for(int i=0;i<n;i++){
             cout<<list[i].s<<"*"<<list[i].e<<endl;
     }*/
    sort(list, list + n, cmp);
    int ans = 1, s = list[0].e;
    for (int i = 1; i < n; i++) {
      if (list[i].s >= s) {
        ans++;
        s = list[i].e;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int s, e;
} list[100005];
bool cmp(node x, node y) { return x.e < y.e; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int x, l;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &x, &l);
      list[i].s = x - l;
      list[i].e = x + l;
    }
    /* for(int i=0;i<n;i++){
             cout<<list[i].s<<"*"<<list[i].e<<endl;
     }*/
    sort(list, list + n, cmp);
    int ans = 1, s = list[0].e;
    for (int i = 1; i < n; i++) {
      if (list[i].s >= s) {
        ans++;
        s = list[i].e;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p02796 (C++)

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

#define all(x) (x).begin(), (x).end()

#define MOD 1000000007

using namespace std;

bool compare(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> arm(n);
  vector<pair<int, int>> range(n);
  for (int i = 0; i < n; i++) {
    cin >> arm[i].first >> arm[i].second;
    range[i].first = arm[i].first + arm[i].second;
    range[i].second = arm[i].first - arm[i].second;
  }
  int ans = 1;
  int g;

  sort(all(range));

  if (n == 1)
    return 1;

  g = range[0].first;
  for (int i = 1; i < n; i++) {
    if (g <= range[i].second) {
      ans++;
      g = range[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define all(x) (x).begin(), (x).end()

#define MOD 1000000007

using namespace std;

bool compare(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> arm(n);
  vector<pair<int, int>> range(n);
  for (int i = 0; i < n; i++) {
    cin >> arm[i].first >> arm[i].second;
    range[i].first = arm[i].first + arm[i].second;
    range[i].second = arm[i].first - arm[i].second;
  }
  int ans = 1;
  int g;

  sort(all(range));

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  g = range[0].first;
  for (int i = 1; i < n; i++) {
    if (g <= range[i].second) {
      ans++;
      g = range[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define maxn 200020
#define ll long long int
using namespace std;

int n;

struct ele {
  int id, l, r;
  ele(int id, int l, int r) : id(id), l(l), r(r) {}
  ele() {}
  bool operator<(const ele b) const {
    return (l == b.l) ? ((r == b.r) ? (id < b.id) : r < b.r) : l < b.l;
  }
} p[maxn];

bool vis[maxn];
int dp[maxn];
int DP(int pos) {
  if (pos == n + 1)
    return 0;
  if (vis[pos])
    return dp[pos];
  int &ans = dp[pos];
  return ans = max(
             DP(pos + 1),
             1 + DP(lower_bound(p + 1, p + 1 + n, ele(-1, p[pos].r, p[pos].r)) -
                    p));
}

int main() {

  // freopen("B.in", "r", stdin);

  int x, y;
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d%d", &x, &y), p[i] = ele(i, x - y, x + y);
  sort(p + 1, p + 1 + n);
  printf("%d", DP(1));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define maxn 200020
#define ll long long int
using namespace std;

int n;

struct ele {
  int id, l, r;
  ele(int id, int l, int r) : id(id), l(l), r(r) {}
  ele() {}
  bool operator<(const ele b) const {
    return (l == b.l) ? ((r == b.r) ? (id < b.id) : r < b.r) : l < b.l;
  }
} p[maxn];

bool vis[maxn];
int dp[maxn];
int DP(int pos) {
  if (pos == n + 1)
    return 0;
  if (vis[pos])
    return dp[pos];
  vis[pos] = 1;
  int &ans = dp[pos];
  return ans = max(
             DP(pos + 1),
             1 + DP(lower_bound(p + 1, p + 1 + n, ele(-1, p[pos].r, p[pos].r)) -
                    p));
}

int main() {

  // freopen("B.in", "r", stdin);

  int x, y;
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d%d", &x, &y), p[i] = ele(i, x - y, x + y);
  sort(p + 1, p + 1 + n);
  printf("%d", DP(1));
  return 0;
}
Problem p02796 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

struct aera {
  int start;
  int end;
};

bool cmp(aera a, aera b) {
  if (a.end != b.end)
    return a.end < b.end;
  else
    return a.start > b.start;
}

int main() {
  aera a1[10010];
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a1[i].start = x - y;
    a1[i].end = x + y;
  }
  sort(a1, a1 + n, cmp);
  int i, count = 1;
  int lastend = a1[0].end;
  for (i = 0; i < n; i++) {
    if (lastend <= a1[i].start) {
      count++;
      lastend = a1[i].end;
    }
  }
  printf("%d\n", count);

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

struct aera {
  int start;
  int end;
};

bool cmp(aera a, aera b) {
  if (a.end != b.end)
    return a.end < b.end;
  else
    return a.start > b.start;
}

int main() {
  aera a1[100005];
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a1[i].start = x - y;
    a1[i].end = x + y;
  }
  sort(a1, a1 + n, cmp);
  int i, count = 1;
  int lastend = a1[0].end;
  for (i = 0; i < n; i++) {
    if (lastend <= a1[i].start) {
      count++;
      lastend = a1[i].end;
    }
  }
  printf("%d\n", count);

  return 0;
}
Problem p02796 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> xl(n);
  vector<pair<int, int>> state(n);
  for (int i = 0; i < n; i++) {
    cin >> xl[i].first >> xl[i].second;
    state[i].first = xl[i].first + xl[i].second;
    state[i].second = xl[i].first - xl[i].second;
  }

  int count = 0;
  sort(state.begin(), state.end());
  for (int i = 0; i < state.size(); i++) {
    if (state[i + 1].second < state[i].first) {
      count++;
      state[i + 1] = state[i];
    }
  }
  cout << n - count << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> xl(n);
  vector<pair<int, int>> state(n);
  for (int i = 0; i < n; i++) {
    cin >> xl[i].first >> xl[i].second;
    state[i].first = xl[i].first + xl[i].second;
    state[i].second = xl[i].first - xl[i].second;
  }

  int count = 0;
  sort(state.begin(), state.end());
  for (int i = 0; i < state.size() - 1; i++) {
    if (state[i + 1].second < state[i].first) {
      count++;
      state[i + 1] = state[i];
    }
  }
  cout << n - count << endl;
  return 0;
}