alexjercan/bugnet huggingface dataset:
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010], B[200010];
ll sumA[200010], sumB[200010];
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    sumA[i + 1] = sumA[i] + A[i];
  for (int i = 0; i < M; i++)
    sumB[i + 1] = sumB[i] + B[i];
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    ll sum = sumA[i];
    int ok = 0;
    int ng = M + 1;
    while (abs(ok - ng) > 1) {
      int mid = (ok + ng) / 2;
      if (sum + sumB[mid] <= K)
        ok = mid;
      else
        ng = mid;
    }
    if (sum <= K)
      ans = max(ans, i + ok);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[100010], B[100010];
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  A[N] = mod;
  B[M] = mod;
  ll sum = 0;
  int i = 0, j = 0;
  int ans = 0;
  while (sum < K) {
    if (i == N && j == M)
      break;
    if (A[i] < B[j])
      sum += A[i++];
    else
      sum += B[j++];
    if (sum <= K)
      ans++;
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

#define froop1(a, n) for (long long i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)
int main() {
  long long N, M, limit;
  cin >> N >> M >> limit;
  vector<long long> N1(N + 1);
  vector<long long> M1(M + 1);
  froop1(1, N + 1) {
    long long a;
    cin >> a;
    N1.at(i) = a;
    N1.at(i) += N1.at(i - 1);
  }
  froop1(1, M + 1) {
    long long a;
    cin >> a;
    M1.at(i) = a;
    M1.at(i) += M1.at(i - 1);
  }

  long long m = 0, best = M;
  froop1(0, N + 1) {
    long long j = best;
    if (N1.at(i) > limit)
      break;
    while (N1.at(i) + M1.at(j) > limit && j > 0) {
      j--;
      best--;
    }
    m = max(m, i + j);
  }
  cout << m << endl;
}


Error: 0

Fixed submission:

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

#define froop1(a, n) for (int i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)
int main() {
  long long N, M, limit;
  cin >> N >> M >> limit;
  vector<long long> N1(N);
  vector<long long> M1(M);
  froop1(0, N) {
    long long a;
    cin >> a;
    N1.at(i) = a;
    if (i != 0) {
      N1.at(i) += N1.at(i - 1);
    }
  }
  froop1(0, M) {
    long long a;
    cin >> a;
    M1.at(i) = a;
    if (i != 0) {
      M1.at(i) += M1.at(i - 1);
    }
  }

  long long m = 0, best = M - 1;
  froop1(0, N) {
    long long j = best;
    if (N1.at(i) > limit)
      break;
    while (N1.at(i) + M1.at(j) > limit) {
      j--;
      best--;
    }
    m = max(m, i + j + 2);
  }
  cout << m << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cout << fixed << setprecision(10);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  vector<ll> c(n + 1, 0);
  vector<ll> d(m + 1, 0);
  rep(i, n) { c[i + 1] = c[i] + a[i]; }
  rep(i, m) { d[i + 1] = d[i] + b[i]; }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (c[i] > k) {
      continue;
    } else {
      int p = k - c[i];
      // cout << p << endl;
      int ok, ng;
      ok = 0;
      ng = m + 1;
      while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        if (d[mid] <= p) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      // cout << ok << endl;
      chmax(ans, i + ok);
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cout << fixed << setprecision(10);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  vector<ll> c(n + 1, 0);
  vector<ll> d(m + 1, 0);
  rep(i, n) { c[i + 1] = c[i] + a[i]; }
  rep(i, m) { d[i + 1] = d[i] + a[i]; }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (c[i] > k) {
      continue;
    } else {
      int p = k - c[i];
      // cout << p << endl;
      int ok, ng;
      ok = 0;
      ng = m + 1;
      while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        if (d[mid] <= p) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      // cout << ok << endl;
      chmax(ans, i + ok);
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge {
  ll to, cost;
};

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll keta(ll N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}

// 回文
bool kai(string S) {
  bool flag = true;
  for (ll i = 0; i < S.size() / 2; ++i) {
    if (S[i] != S[S.size() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
// ---------------------------------------------

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  a[0] = 0;
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    a[i + 1] = a[i] + x;
  }
  vector<ll> b(m + 1);
  b[0] = 0;
  for (ll i = 0; i < m; ++i) {
    ll x;
    cin >> x;
    b[i + 1] = b[i] + x;
  }

  ll ans = 0;
  ll index = m;
  for (ll i = 0; i < n + 1; ++i) {
    for (ll j = index; j >= 0; --j) {
      if (a[i] + b[j] <= k) {
        ans = max(ans, i + j);
        index = j;
        break;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge {
  ll to, cost;
};

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll keta(ll N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}

// 回文
bool kai(string S) {
  bool flag = true;
  for (ll i = 0; i < S.size() / 2; ++i) {
    if (S[i] != S[S.size() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
// ---------------------------------------------

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  a[0] = 0;
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    a[i + 1] = a[i] + x;
  }
  vector<ll> b(m + 1);
  b[0] = 0;
  for (ll i = 0; i < m; ++i) {
    ll x;
    cin >> x;
    b[i + 1] = b[i] + x;
  }

  ll ans = 0;
  for (ll i = 0; i < n + 1; ++i) {
    for (ll j = m; j >= 0; --j) {
      if (a[i] + b[j] <= k) {
        ans = max(ans, i + j);
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI = acos(-1);

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  vector<ll> as(n + 1, 0), bs(m + 1, 0);
  rep(i, n) {
    cin >> a[i];
    as[i + 1] = as[i] + a[i];
  }
  rep(i, m) {
    cin >> b[i];
    bs[i + 1] = bs[i] + b[i];
  }
  ll ans = 0, j = m;
  rep(i, n + 1) {
    if (as[i] > k)
      break;
    while (bs[j] > k - as[i])
      j--;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI = acos(-1);

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  vector<ll> as(n + 1, 0), bs(m + 1, 0);
  rep(i, n) {
    cin >> a[i];
    as[i + 1] = as[i] + a[i];
  }
  rep(i, m) {
    cin >> b[i];
    bs[i + 1] = bs[i] + b[i];
  }
  ll ans = 0, j = m;
  rep(i, n + 1) {
    if (as[i] > k)
      break;
    while (bs[j] >= k - as[i])
      j--;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  int book_num1, book_num2;
  int limit_min;
  vector<ll> accume_times1, accume_times2;

  // Init
  cin >> book_num1 >> book_num2 >> limit_min;

  accume_times1.resize(book_num1 + 1);
  accume_times2.resize(book_num2 + 1);
  for (int i = 1; i <= book_num1; i++) {
    cin >> accume_times1[i];
  }
  for (int i = 1; i <= book_num2; i++) {
    cin >> accume_times2[i];
  }

  // Calc accum
  accume_times1[0] = 0;
  for (int i = 1; i <= book_num1; i++) {
    accume_times1[i] += accume_times1[i - 1];
  }
  accume_times2[0] = 0;
  for (int i = 1; i <= book_num2; i++) {
    accume_times2[i] += accume_times2[i - 1];
  }

  int max_book_num = 0;
  int current_book2_num = book_num2;
  for (int i = 0; i <= book_num1; i++) {
    ll read_time;

    while (true) {
      read_time = accume_times1[i] + accume_times2[current_book2_num];
      if (read_time <= limit_min || current_book2_num == 0) {
        break;
      }
      current_book2_num--;
    }

    if (read_time <= limit_min) {
      max_book_num = max(max_book_num, i + current_book2_num);
    }
  }

  cout << max_book_num << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  int book_num1, book_num2;
  int limit_min;
  vector<ll> accume_times1, accume_times2;

  // Init
  cin >> book_num1 >> book_num2 >> limit_min;

  accume_times1.resize(book_num1 + 1);
  accume_times2.resize(book_num2 + 1);
  for (int i = 1; i <= book_num1; i++) {
    cin >> accume_times1[i];
  }
  for (int i = 1; i <= book_num2; i++) {
    cin >> accume_times2[i];
  }

  // Calc accum
  accume_times1[0] = 0;
  for (int i = 1; i <= book_num1; i++) {
    accume_times1[i] += accume_times1[i - 1];
  }
  accume_times2[0] = 0;
  for (int i = 1; i <= book_num2; i++) {
    accume_times2[i] += accume_times2[i - 1];
  }

  int max_book_num = 0;
  for (int i = 0; i <= book_num1; i++) {
    for (int j = 0; j <= book_num2; j++) {
      ll read_time = accume_times1[i] + accume_times2[j];
      if (read_time > limit_min) {
        break;
      }

      max_book_num = max(max_book_num, i + j);
    }
  }

  cout << max_book_num << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define cio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];
ll nu_b[200005];

ll n, m, k;

ll bin(int st, int en, ll val) {
  if (en - st <= 1)
    return st;

  int mi = (st + en) / 2;
  ll look = nu_b[mi];

  if (look == val)
    return mi;
  else if (look < val)
    return bin(mi, en, val);
  else
    return bin(st, mi, val);
}

int main() {
  cio;
  cin >> n >> m >> k;

  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  for (ll i = 1; i <= m; i++) {
    ll inp;
    cin >> inp;
    nu_b[i] = nu_b[i - 1] + inp;
  }

  ll ma = 0;
  ll nu_a = 0;
  for (ll i = 0; i <= n; i++) {
    nu_a += arr[i];

    if (nu_a > k)
      break;

    ma = max(ma, i + bin(0, m + 1, k - nu_a));
  }

  cout << ma;
}

Error: TLE

Fixed submission:

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

#define cio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];
ll brr[200005];

int main() {
  cio;
  ll n, m, k;
  cin >> n >> m >> k;

  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  for (ll i = 1; i <= m; i++)
    cin >> brr[i];

  ll ma = 0;
  ll nu_a = 0;
  for (ll i = 0; i <= n; i++) {
    nu_a += arr[i];

    if (nu_a > k)
      break;

    ll nu_b = 0;

    for (ll j = 0; j <= m; j++) {
      nu_b += brr[j];
      if (nu_a + nu_b > k)
        break;

      ma = max(ma, i + j);
    }
  }

  cout << ma;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define per1(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vec A(n), B(m), C(n + 1), D(m + 1);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];
  ll ans = 0;
  rep(i, n) C[i + 1] = A[i] + C[i];
  rep(i, m) D[i + 1] = B[i] + D[i];
  rep(i, n + 1) {
    if (k >= C[i])
      ans = max(ans, (ll)i + (upper_bound(all(D), k - C[i]) - D.begin()) - 1);
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define per1(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vec A(n), B(m), C(n + 1), D(n + 1);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];
  ll ans = 0;
  rep(i, n) C[i + 1] = A[i] + C[i];
  rep(i, m) D[i + 1] = B[i] + D[i];
  rep(i, n + 1) {
    if (k >= C[i])
      ans = max(ans, (ll)i + (lower_bound(all(D), k - C[i]) - D.begin()));
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
int n, m, k;
int a[200000], b[200000];
int suma[200000], sumb[200000];
vector<int> t;
signed main() {
  cin >> n >> m >> k;
  rep(i, n) {
    cin >> a[i];
    if (i == 0)
      suma[0] = a[0];
    else
      suma[i] = suma[i - 1] + a[i];
  }
  rep(i, m) {
    cin >> b[i];
    if (i == 0)
      sumb[0] = b[0];
    else
      sumb[i] = sumb[i - 1] + b[i];
  }
  rep(i, n + 1) {
    int x;
    if (i == 0)
      x = k;
    else
      x = k - suma[i - 1];
    if (x < 0)
      break;
    t.push_back(i + (upper_bound(sumb, sumb + m, x) - sumb));
  }
  sort(all(t));
  int l = t.size();
  cout << t[l - 1] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
int n, m, k;
queue<int> a, b;
int ans = 0;
signed main() {
  cin >> n >> m >> k;
  rep(i, n) {
    int x;
    cin >> x;
    a.push(x);
  }
  rep(i, m) {
    int x;
    cin >> x;
    b.push(x);
  }
  while (k > 0) {
    if (a.empty() && b.empty())
      break;
    if (b.empty() || a.front() <= b.front()) {
      if (k >= a.front())
        ans++;
      k -= a.front();
      a.pop();
    } else {
      if (k >= b.front())
        ans++;
      k -= b.front();
      b.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define INF 1000000100
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  int a[N], b[M];
  rep(i, N) cin >> a[i];
  rep(i, M) cin >> b[i];

  ll A[N + 1], B[M + 1];
  A[0] = B[0] = 0;
  for (int i = 1; i <= N; i++) {
    A[i] = A[i - 1] + a[i - 1];
  }
  for (int j = 1; j <= M; j++) {
    B[j] = B[j - 1] + b[j - 1];
  }

  int j = M;
  int ans = 0;
  rep(i, N + 1) {
    if (A[i] > K)
      break;
    while (B[j] > K - A[i])
      j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define INF 1000000100
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  int a[N], b[M];
  rep(i, N + 10) a[i] = INF;
  rep(i, M + 10) b[i] = INF;
  rep(i, N) cin >> a[i];
  rep(i, M) cin >> b[i];

  int i = 0, j = 0;
  int ans = 0;
  while (K > 0 && (i < N || j < M)) {
    if (a[i] <= b[j] && i < N) {
      K -= a[i];
      i++;
    } else if (j < M) {
      K -= b[j];
      j++;
    }
    if (K >= 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N + 1);
  vector<int> B(M + 1);
  vector<int> C(N + 1);
  vector<int> D(M + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    C[i] = C[i - 1] + A[i];
  }
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    D[i] = D[i - 1] + B[i];
  }
  vector<int> E(N + 1, 0);
  int count = M;
  for (int i = 0; i <= N; i++) {
    for (int j = count; j >= 0; j--) {
      if (K >= C[i] + D[j]) {
        E[i] = i + j;
        count = j;
        break;
      }
    }
  }
  sort(E.begin(), E.end());
  cout << E[N] << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  bool C = true;
  bool D = true;
  bool E = true;
  bool F = true;
  int ans = 0;
  int count = 0;
  int ca = 0;
  int cb = 0;
  for (; cb < N;) {
    for (; ca < M;) {
      if (count + min(A[cb], B[ca]) > K) {
        C = false;
        break;
      }
      if (A[cb] >= B[ca]) {
        ans++;
        count += B[ca];
        ca++;
        if (ca == M) {
          D = false;
          break;
        }
        continue;
      } else {
        E = false;
        break;
      }
    }
    if (E == false) {
      ans++;
      count += A[cb];
      cb++;
      E = true;
      if (cb == N) {
        F = false;
        break;
      }
    }
    if (C == false) {
      break;
    }
    if (D == false) {
      break;
    }
  }
  if (D == false) {
    for (; cb < N;) {
      if (count + A[cb] > K) {
        break;
      }
      ans++;
      count += A[cb];
      cb++;
    }
  }
  if (F == false) {
    for (; ca < M;) {
      if (count + B[ca] > K) {
        break;
      }
      ans++;
      count += B[ca];
      ca++;
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  long long k;
  cin >> n >> m >> k;
  long long asum = 0;
  vector<long long> a;
  vector<long long> b;
  long long book;
  for (int i = 0; i < n; i++) {
    cin >> book;
    asum += book;
    a.push_back(asum);
  }
  long long bsum = 0;
  for (int i = 0; i < m; i++) {
    cin >> book;
    bsum += book;
    b.push_back(bsum);
  }
  int j = m - 1;
  while (j >= 0 && b[j] > k) {
    j--;
  }
  int sol = j + 1;
  for (int i = 0; i < n; i++) {
    while (j >= 0 && a[i] + b[j] > k) {
      j--;
    }
    if (i + j + 2 > sol && a[i] <= k) {
      sol = i + j + 2;
    }
  }
  cout << sol << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, k, tmp, cnt = 0;
  cin >> n >> m >> k;

  queue<int> a;
  queue<int> b;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a.push(tmp);
  }

  for (int i = 0; i < m; i++) {
    cin >> tmp;
    b.push(tmp);
  }

  for (int i = 0; i < n + m; i++) {
    if (a.front() < b.front()) {
      tmp = a.front();
      a.pop();
      k -= tmp;
      if (k >= 0) {
        cnt++;
      } else {
        break;
      }
    } else {
      tmp = b.front();
      b.pop();
      k -= tmp;
      if (k >= 0) {
        cnt++;
      } else {
        break;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}