alexjercan/bugnet huggingface dataset:
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef pair<int, int> P;

int main() {
  int n;
  while (cin >> n) {
    vector<int> a(100010);
    vector<int> b(100010);
    REP(i, n) {
      int t1, t2;
      cin >> t1 >> t2;
      a[t1]++;
      b[t2]++;
    }
    int ans = 0;
    int member = 0;
    for (int i = 0; i <= n; i++) {
      member += a[i + 1];
      member -= b[i];
      if (member >= i)
        ans = i;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef pair<int, int> P;

int main() {
  int n;
  while (cin >> n) {
    vector<int> a(n);
    vector<int> b(n);
    REP(i, n) cin >> a[i] >> b[i];
    for (int i = n; i >= 0; i--) {
      int count = 0;
      REP(j, n) if (a[j] <= i + 1 && i + 1 <= b[j]) { count++; }
      if (count >= i) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REP(i, a) for (long i = 0; i < (a); ++i)

typedef std::vector<int> VI;

int N;
VI imos(100002, 0);
int main() {
  std::cin >> N;

  REP(i, N) {
    int a, b;
    std::cin >> a >> b;
    ++imos[a];
    --imos[b + 1];
  }

  int x = 0, ans = 0;
  for (int i = 0; i <= N + 1; ++i) {
    x += imos[i];
    if (x + 1 >= i) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, a) for (long i = 0; i < (a); ++i)

typedef std::vector<int> VI;

int N;
VI imos;
int main() {
  std::cin >> N;
  imos.resize(N + 3, 0);

  REP(i, N) {
    int a, b;
    std::cin >> a >> b;
    ++imos[a];
    --imos[b + 1];
  }

  int x = 0, ans = 0;
  for (int i = 0; i <= N + 1; ++i) {
    x += imos[i];
    if (x + 1 >= i) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, a, b, ans, s, t;
  cin >> N;
  vector<int> A, B;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  ans = 0;
  vector<int>::iterator itr1, itr2;
  for (int i = N + 1; i > 0; --i) {
    itr1 = lower_bound(A.begin(), A.end(), i + 1);
    itr2 = lower_bound(B.begin(), B.end(), i);
    s = distance(A.begin(), itr1);
    t = distance(B.begin(), itr2);
    if (s - t >= i - 1) {
      ans = i - 1;
      break;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, a, b, ans, t;
  cin >> N;
  vector<int> A, B;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  ans = 0;
  for (int i = N + 1; i > 0; --i) {
    t = 1;
    for (int j = 0; j < N; ++j) {
      if (i >= A[j] && i <= B[j])
        t++;
    }
    if (t >= i)
      ans = max(ans, i - 1);
  }
  cout << ans << endl;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

#define MAX 1e05 + 1

int main(void) {
  int n;
  cin >> n;
  int start;
  int end;
  VI table(MAX + 1, 0);

  for (int i = 0; i < n; i++) {
    cin >> start >> end;
    start--;
    end--;
    for (int j = start; j <= end; j++) {
      table[j]++;
    }
  }
  /*
  for (int i = 0; i < 10; i++) {
      cout << i << ", " << table[i] << endl;
  }
  */
  for (int i = MAX; i >= 0; i--) {
    if (i <= table[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int n;

bool check(VVI &table, int number) {
  // number ?????????????????????
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (table[i][0] <= number && table[i][1] >= number) {
      count++;
    }
  }
  if (count >= number - 1) {
    return true;
  } else {
    return false;
  }
}

int main(void) {
  cin >> n;
  VVI table(n, VI(2));
  for (int i = 0; i < n; i++) {
    cin >> table[i][0] >> table[i][1];
  }

  for (int i = n + 1; i >= 1; i--) {
    if (check(table, i) == true) {
      cout << i - 1 << endl;
      return 0;
    }
  }

  /*
     int left = 1;
     int right = n + 1;
     while (left < right) {
     int middle = (left + right) / 2 + 1;
     if (check(table, middle) == true) {
     left = middle;
     } else {
     right = middle - 1;
     }
     }
     cout << left - 1 << endl;
   */

  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> f(131072, 0);
  REP(i, n) {
    int l, r;
    cin >> l >> r;
    ++f[l];
    --f[r + 1];
  }
  ++f[0];
  REP(i, 131000) f[i + 1] += f[i];
  int answer = 0;
  REP(i, 131000) if (f[i] >= i) answer = i - 1;
  cout << answer << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  for (;;) {
    int n;
    cin >> n;
    if (!n)
      return 0;
    vector<int> f(131072, 0);
    REP(i, n) {
      int l, r;
      cin >> l >> r;
      ++f[l];
      --f[r + 1];
    }
    ++f[0];
    REP(i, 131000) f[i + 1] += f[i];
    int answer = 0;
    REP(i, 131000) if (f[i] >= i) answer = i - 1;
    cout << answer << endl;
  }
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REP(i, a) for (long i = 0; i < (a); ++i)

typedef std::vector<int> VI;

int N;
VI imos(100002, 0);
int main() {
  std::cin >> N;

  REP(i, N) {
    int a, b;
    std::cin >> a >> b;
    ++imos[a];
    --imos[b + 1];
  }

  int x = 0, ans = 0;
  for (int i = 0; i <= N + 1; ++i) {
    x += imos[i];
    if (x + 1 >= i) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, a) for (long i = 0; i < (a); ++i)

typedef std::vector<int> VI;

int N;
VI imos;
int main() {
  std::cin >> N;
  imos.resize(N + 5, 0);

  REP(i, N) {
    int a, b;
    std::cin >> a >> b;
    ++imos[a];
    --imos[b];
  }

  int x = 0, ans = 0;
  for (int i = 0; i <= N + 1; ++i) {
    x += imos[i];
    if (x + 1 >= i) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
  int N;
  cin >> N;
  std::vector<int> frimin(N);
  std::vector<int> frimax(N);
  for (int i = 0; i < N; i++) {
    cin >> frimin[i] >> frimax[i];
  }

  std::sort(frimin.begin(), frimin.end());
  std::sort(frimax.begin(), frimax.end());

  int ret = 0;
  int count = 1;
  int imin = -1;
  int imax = -1;
  for (int f = 2; f < N + 2 && f <= frimax[N - 1]; f++) {
    for (int i = imin + 1; frimin[i] == f; i++) {
      count++;
      imin++;
    }
    for (int i = imax + 1; frimax[i] == f - 1; i++) {
      count--;
      imax++;
    }

    if (count >= f && count != 1) {
      ret = f - 1;
    }
  }

  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

struct data_t {
  int min;
  int max;

  bool operator<(const data_t &right) const {
    if (min == right.min) {
      return ((max < right.max) || (max == right.max));
    } else {
      return (min < right.min);
    }
  }
};

int main(void) {
  int N;
  cin >> N;
  std::vector<data_t> fri(N);
  int fmin = 100001;
  for (int i = 0; i < N; i++) {
    cin >> fri[i].min >> fri[i].max;
    if (fri[i].min < fmin) {
      fmin = fri[i].min;
    }
  }

  int ret = 0;
  int count;
  for (int f = fmin; f < N + 2; f++) {
    count = 1;
    for (int i = 0; i < N; i++) {
      if (fri[i].min <= f && fri[i].max >= f) {
        count++;
      } else {
      }
    }

    if (count != 1 && count > ret) {
      if (count >= f) {
        ret = f - 1;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

static int member[101010];

void solve() {
  int n, a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    member[a]++;
    member[b + 1]--;
  }
  partial_sum(begin(member), end(member), begin(member));
  for (int i = 101009; i > 0; i--) {
    if (member[i] >= i - 1) {
      cout << i - 1 << "\\n";
      return;
    }
  }
}

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

Error: -11

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

static int member[100004];

void solve() {
  int n, a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    member[a]++;
    member[b + 1]--;
  }
  partial_sum(begin(member), end(member), begin(member));
  for (int i = 1e6 + 1; i > 0; i--) {
    if (member[i] >= i - 1) {
      cout << i - 1 << "\\n";
      return;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  solve();
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int n;
int cnt[100005];

int main() {
  cin >> n;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int j = a; j < b + 1; j++) {
      cnt[j]++;
    }
  }

  int ans = 0;
  for (int i = 1; i < n + 2; i++) {
    if (i <= cnt[i] + 1)
      ans = i - 1;
  }
  cout << ans << endl;
  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int n;

int main() {
  cin >> n;
  vector<vector<int>> ab(n + 2, vector<int>(0));
  vector<int> away(n + 2, 0);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a < n + 2)
      ab[a].push_back(b);
  }
  sort(ab.begin(), ab.end());
  int count = 1;
  int m = 1;
  for (int j = 1; j < n + 2; j++) {
    if (ab[j].size() == 0)
      continue;
    if (count + ab[j].size() < j) {
      count = count + ab[j].size();
      for (int k = 1; k <= ab[j].size(); k++) {
        away[(int)ab[j][k - 1] + 1]++;
      }
      continue;
    }
    for (int k = 1; k <= ab[j].size(); k++) {
      count++;
      count -= away[count];
      // cout << count << endl;
      m = max(m, count);
      away[(int)ab[j][k - 1] + 1]++;
    }
  }
  // for(int k = 0; k < n + 2; k++) cout << away[k] << endl;
  cout << m - 1 << endl;
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 100005;

int a[MAX_N], b[MAX_N];
int n;
int imos[MAX_N];
int sch[MAX_N];

int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d%d", &a[i], &b[i]);
    imos[a[i]]++;
    imos[b[i] + 1]--;
  }
  sch[0] = imos[0];
  rep(i, 100002) { sch[i + 1] = sch[i] + imos[i + 1]; }
  int res = -1;
  rep(i, 100002) {
    if (sch[i] >= i - 1 && i > res) {
      res = i;
    }
  }
  cout << res - 1 << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 100005;

int a[MAX_N], b[MAX_N];
int n;

bool possible(int u) {
  int cnt = 0;
  if (u == 0) {
    return true;
  }
  rep(i, n) {
    if (a[i] <= u + 1 && b[i] >= u + 1) {
      cnt++;
      if (cnt >= u) {
        return true;
      }
    }
  }
  return false;
}

int main() {
  scanf("%d", &n);
  rep(i, n) { scanf("%d%d", &a[i], &b[i]); }
  int res = -1;
  rep(i, n + 1) {
    if (possible(i) && i > res) {
      res = i;
    }
  }
  cout << res << "\\n";
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, a, b;
int member[100004];
int sum;
;

int main() {
  member[1] = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    member[a]++;
    member[b + 1]--;
  }
  sum = 0;
  for (int i = 1; i <= n; i++) {
    member[i + 1] += member[i];
    if (i + 1 <= member[i + 1])
      sum = i;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n;
int a[100000];
int b[100000];
int count;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int sum;
  for (sum = n + 1; sum > 0; sum--) {
    count = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] <= sum && sum <= b[i])
        count++;
      if (count == sum)
        break;
    }
    if (count == sum)
      break;
  }
  cout << sum - 1 << endl;
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  vector<int> F;

  cin >> N;
  for (int i = 0; i < N + 1; i++) {
    F.push_back(0);
  }

  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;

    int xn = max(0, x - 1);
    if (xn <= N) {
      F[xn]++;
    }
    if (y <= N) {
      F[y]--;
    }
  }

  for (int i = 0; i < N; i++) {
    F[i + 1] += F[i];
  }

  int ans;
  for (int i = 0; i < N + 1; i++) {
    if (F[i] >= i) {
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  vector<int> F;

  cin >> N;
  for (int i = 0; i < N + 1; i++) {
    F.push_back(0);
  }

  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;

    int xn = max(0, x - 1);
    F[xn]++;
    if (y <= N) {
      F[y]--;
    }
  }

  for (int i = 0; i < N; i++) {
    F[i + 1] += F[i];
  }

  int ans;
  for (int i = 0; i < N + 1; i++) {
    if (F[i] >= i) {
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rangeRep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)

int canGo[100001] = {0};

class Solve {
public:
  Solve(){};
  ~Solve(){};

  void solver() {
    int ans = 0;
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> friends(n, std::make_pair(0, 0));
    rep(i, n) {
      std::cin >> friends[i].first >> friends[i].second;
      // Exclude myself
      friends[i].first--;
      friends[i].second--;
    }
    // Record the number of people who can go.
    for (auto &x : friends) {
      rangeRep(i, x.first, x.second + 1) { canGo[i]++; }
    }
    int max = 0;
    rep(i, n + 1) {
      if (canGo[i] >= i) {
        max = i;
      }
    }
    std::cout << max << std::endl;
  }

private:
};

int main() {
  Solve solve;
  solve.solver();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rangeRep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)

class Solve {
public:
  Solve(){};
  ~Solve(){};

  void solver() {
    int ans = 0;
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> friends(n, std::make_pair(0, 0));
    rep(i, n) {
      std::cin >> friends[i].first >> friends[i].second;
      // Exclude myself
      friends[i].first--;
      friends[i].second--;
    }
    // the number of people to take i.
    rangeRep(i, 1, n + 1) {
      int num = 0;
      // check if I can take friend.
      rep(j, n) {
        if (friends[j].first <= i && i <= friends[j].second) {
          num++;
        }
      }
      // There are enough people who said OK
      if (num >= i && ans < num) {
        ans = i;
      }
    }
    std::cout << ans << std::endl;
  }

private:
};

int main() {
  Solve solve;
  solve.solver();
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>

int main(void) {
  int n;
  std::cin >> n;
  int endmax = 0;

  int *pn = new int[100000];
  memset(pn, 0, 100000 * sizeof(int));

  for (int i = 0; i < n; i++) {
    int beg, end;
    std::cin >> beg >> end;
    for (int i = beg; i <= end; i++)
      pn[i]++;
    if (end > endmax)
      endmax = end;
  }

  int mps = 1;
  for (int i = 1; i <= endmax; i++) {
    if (pn[i] + 1 >= i)
      mps = i;
  }

  std::cout << (mps - 1) << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

struct Range {
  int beg;
  int end;
};

int main(void) {
  int n;
  std::cin >> n;

  Range *ps = new Range[n];

  for (int i = 0; i < n; i++)
    std::cin >> ps[i].beg >> ps[i].end;

  //	i???"?????????"??????????????°
  int mps = 1;
  for (int i = 1; i <= n + 1; i++) {
    int cps = 0;
    bool f = false;
    for (int j = 0; j < n; j++) {
      if (i >= ps[j].beg && i <= ps[j].end) {
        cps++;
        if (cps >= i - 1) {
          f = true;
          break;
        }
      }
    }
    if (f)
      mps = i;
  }

  std::cout << (mps - 1) << '\\n';

  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

signed main() {
  int i;
  int N = read();
  int ans = 0;
  int a[100010] = {0}, b[100010] = {0};
  int sum[N + 3] = {0};

  sum[0] = 1; // include me

  REP(i, N) {
    a[read()]++;
    b[read() + 1]--;
  }

  for (i = 1; i <= N + 1; i++) {
    sum[i] += sum[i - 1] + a[i] + b[i];
    // cout << sum[i] << endl;
  }

  for (i = 1; i <= N + 1; i++) {
    if (sum[i] >= i) {
      ans = i - 1;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  int maxn = 0;
  vector<pair<int, int>> friends;
  vector<int> humans;
  vector<int> nokemono;

  // INPUT
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    friends.push_back(make_pair(a, b));
  }
  // UPCOUNT & DOWNCOUNT
  for (int i = 0; i <= N + 1; i++) {
    int count = 0;
    int minn = 999999;
    for (auto range : friends) {
      if (i >= range.first && i <= range.second) {
        count++;
        if (range.second < minn)
          minn = range.second;
      }
    }
    count++;
    humans.push_back(count);
    if (minn == 999999)
      minn = 0;
    nokemono.push_back(minn);
    count = 0;

    if (humans[i] < nokemono[i])
      nokemono[i] = humans[i];
    if (humans[i] < i) {
      // cout << i << endl;
      nokemono[i] = 0;
    }
    if (nokemono[i] > maxn)
      maxn = nokemono[i];
    // if(nokemono[i] < humans[i]) nokemono[i] = 0;
    // cout << i << ":" << humans[i] << "," << nokemono[i] << endl;
    // cout << i << "," << humans[i]-1 << endl;
    // flag = false;
    // break;
  }

  /*
  //bool flag = true;
  int maxn = 0;
  for(int i=N+1;i>0;i--){
          if(humans[i] < nokemono[i]) nokemono[i] = humans[i];
          if(humans[i] < i){
                  //cout << i << endl;
                  nokemono[i] = 0;
          }
          if(nokemono[i] > maxn) maxn = nokemono[i];
          //if(nokemono[i] < humans[i]) nokemono[i] = 0;
          //cout << i << ":" << humans[i] << "," << nokemono[i] << endl;
          //cout << i << "," << humans[i]-1 << endl;
          //flag = false;
          //break;
  }
  */

  cout << max(0, maxn - 1) << endl;
  return 0;
}
Problem p01448 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> V(100005);
  V[0]++;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    V[a]++;
    V[b + 1]--;
  }

  int res = 0;
  for (int i = 0; i <= 100001; i++) {
    V[i + 1] += V[i];
    if (i <= V[i])
      res = i;
  }

  cout << res - 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N + 5);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    V[a]++;
    V[b + 1]--;
  }

  int res = 0;
  for (int i = 0; i <= N; i++) {
    V[i + 1] += V[i];
    if (i <= V[i] + 1)
      res = i;
  }

  cout << res - 1 << endl;

  return 0;
}