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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>; // グラフ型

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<ll> sa(n + 1);
  rep(i, n) { sa[i + 1] = a[i] + sa[i]; }
  vector<ll> sb(m + 1);
  rep(i, m) { sb[i + 1] = b[i] + sb[i]; }

  int ans = 0;

  rep(i, n + 1) {
    ll k2 = k - sa[i];
    if (k2 < 0)
      continue;
    auto c = upper_bound(sb.begin(), sb.end(), k2);
    int j = distance(sb.begin(), c);
    ans = max(ans, i + j - 1);
  }

  cout << ans << endl;
}

/*
sb = 0,1,5,7,8,9
5 = 3
4 = 2
0 = 1
*/

/*
g++ b.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
oj t
*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>; // グラフ型

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<ll> sa(n + 1);
  rep(i, n) { sa[i + 1] = a[i] + sa[i]; }
  vector<ll> sb(m + 1);
  rep(i, m) { sb[i + 1] = a[i] + sb[i]; }

  int ans = 0;

  rep(i, n + 1) {
    ll k2 = k - sa[i];
    if (k2 < 0)
      continue;
    auto c = upper_bound(sb.begin(), sb.end(), k2);
    int j = distance(sb.begin(), c);
    ans = max(ans, i + j - 1);
  }

  cout << ans << endl;
}

/*
sb = 0,1,5,7,8,9
5 = 3
4 = 2
0 = 1
*/

/*
g++ b.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
oj t
*/
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

const int MOD = 1000000007;
const int INF = 1000000010;

int main() {
  long long n, m, k;
  const int max_n = 2 * 1e5;
  cin >> n >> m >> k;
  long long a[max_n + 10], b[max_n + 10];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];

  long long sum_a[max_n + 10];
  long long sum_b[max_n + 10];
  for (int i = 0; i <= n; i++) {
    if (i == 0)
      sum_a[i] = 0;
    else
      sum_a[i] = sum_a[i - 1] + a[i - 1];
  }
  for (int i = 0; i <= m; i++) {
    if (i == 0)
      sum_b[i] = 0;
    else
      sum_b[i] = sum_b[i - 1] + b[i - 1];
  }
  long long time = 0;
  long long ans = 0;
  long long j = 0;
  long long past = 0;
  sum_b[m + 1] = INF;
  for (long long i = n; i >= 0; i--) {
    if (sum_a[i] > k)
      continue;
    while (sum_a[i] + sum_b[j] <= k) {
      if (j == m + 1)
        break;
      j++;
      // if(j >= m) break;
    }
    ans = max(ans, i + j - 1);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

const int MOD = 1000000007;
const long long INF = 1e12;

int main() {
  long long n, m, k;
  const int max_n = 2 * 1e5;
  cin >> n >> m >> k;
  // long long a[max_n + 10], b[max_n + 10];
  vector<long long> a(n + 1);
  vector<long long> b(m + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  a[n] = INF;
  b[n] = INF;

  long long nowa = 0;
  long long nowb = 0;
  long long ans = 0;

  while (k >= 0) {
    if (a[nowa] >= b[nowb] && k - b[nowb] >= 0) {
      // read b
      k -= b[nowb];
      nowb++;
    } else if (a[nowa] < b[nowb] && k - a[nowa] >= 0) {
      // read a
      k -= a[nowa];
      nowa++;
    } else
      break;
    ans++;
    if (nowa == n && nowb == m)
      break;
  }
  // bool flag = 0;
  // while(k >= 0){
  //   if(a[nowa] <= b[nowb]) flag = 0;
  //   else flag = 1;
  //   if(!flag){
  //     if(k - a[nowa] >= 0){
  //       k -= a[nowa];
  //       nowa ++;
  //     }else break;
  //   }else{
  //     if(k - b[nowb] >= 0){
  //       k -= b[nowb];
  //       nowb ++;
  //     }else break;
  //   }
  //   ans ++;
  //   if(nowa >= n && nowb >= m) break;
  // }

  cout << ans << endl;

  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int A[N], B[N];

int main() {
  int t = 1;
  // cin >> t;
  while (t--) {
    int n, m, ms;
    scanf("%d%d%d", &n, &m, &ms);

    for (int A_i = 0; A_i < n; A_i++) {
      scanf("%d", &A[A_i]);
    }
    for (int B_i = 0; B_i < m; B_i++) {
      scanf("%d", &B[B_i]);
    }

    long long sum = 0;
    int x = 0, y = 0;

    while (x < n && sum + A[x] <= ms) {
      sum += A[x++];
    }

    int ans = x;

    while (y < m && x >= 0) {
      sum += B[y++];
      while (sum > ms && x > 0) {
        sum -= A[--x];
      }

      if (sum <= ms && ans < x + y) {
        ans = x + y;
      }
    }

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


Error: 0

Fixed submission:


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

int A[100002], B[100002];

int main() {
  int t = 1;
  // cin >> t;
  while (t--) {
    int n, m, ms;
    scanf("%d%d%d", &n, &m, &ms);

    for (int A_i = 0; A_i < n; A_i++) {
      scanf("%d", &A[A_i]);
    }
    for (int B_i = 0; B_i < m; B_i++) {
      scanf("%d", &B[B_i]);
    }

    long long sum = 0;
    int x = 0, y = 0;

    while (x < n && sum + A[x] <= ms) {
      sum += A[x++];
    }

    int ans = x;

    while (y < m && x >= 0) {
      sum += B[y++];
      while (sum > ms && x > 0) {
        sum -= A[--x];
      }

      if (sum <= ms && ans < x + y) {
        ans = x + y;
      }
    }

    printf("%d\\n", ans);
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
int n, m, k;

int main() {
  cin >> n >> m >> k;
  vector<int> a(n + 1, 0);
  vector<int> b(m + 1, 0);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    sum += b[i];
  }
  int ans = 0;
  int bi = m;
  for (int i = 0; i <= n; ++i) {
    sum += a[i];
    while (sum > k && bi >= 0)
      sum -= b[bi--];
    if (sum > k)
      break;
    ans = max(ans, bi + i);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, m, k;

int main() {
  cin >> n >> m >> k;
  vector<int> a(n + 1, 0);
  vector<int> b(m + 1, 0);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    sum += b[i];
  }
  int ans = 0;
  int bi = m;
  for (int i = 0; i <= m; ++i) {
    sum += a[i];
    while (sum > k && bi >= 0)
      sum -= b[bi--];
    ans = max(ans, bi + i);
  }
  cout << ans << endl;
}
Problem p02623 (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 <stdio.h>
#include <vector>
#define ll long long
using namespace std;
ll a[200050];
ll b[200050];
int ans;
int main() {
  int n, m, k, t;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  for (int i = 0, j = m; i <= n; i++) {
    if (a[i] <= k) {
      while (a[i] + b[j] > k)
        j--;
      ans = max(ans, i + j);
    }
  }
  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 <stdio.h>
#include <vector>
#define ll long long
using namespace std;
ll a[2000050];
ll b[2000050];

int main() {
  ll n, m, k;
  ll x;
  ll sum = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[i] = a[i - 1] + x;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    b[i] = b[i - 1] + x;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (a[i] + b[j] <= k) {
        if (i + j > sum) {
          sum = i + j;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
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++)

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n + 1, 0);
  vector<long> b(m + 1, 0);

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }

  int b_sum = m, max = 0;
  for (int i = 0; i <= n && a[i] <= k; i++) {
    while (a[i] + b[b_sum] > k)
      b_sum--;
    if (i + b_sum > max)
      max = i + b_sum;
  }

  cout << max << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n + 1, 0);
  vector<long> b(m + 1, 0);

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }

  int b_sum = m, max = 0;
  for (int i = 0; i <= n; i++) {
    while (a[i] + b[b_sum] > k)
      b_sum--;
    if (i + b_sum > max)
      max = i + b_sum;
  }

  cout << max << 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;
using P = pair<int, int>;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m), as(n + 1), bs(m + 1);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  rep(i, n) as[i + 1] = as[i] + a[i];
  rep(i, m) bs[i + 1] = bs[i] + b[i];
  int index = 0;
  rep(i, n + 1) {
    if (as[i] <= k)
      index = i;
    else
      break;
  }
  ll ans = index;
  if (as[n] + bs[m] <= k) {
    cout << n + m << endl;
    return 0;
  }
  rep(i, index + 1) {
    int t = k - as[i];
    int s = upper_bound(bs.begin(), bs.end(), t) - bs.begin();
    if (s > 0) {
      if (bs[s - 1] <= t)
        ans = max(ans, i + s - 1);
    }
    // cout << t << " " << i << " " << s << endl;
  }
  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;
using P = pair<int, int>;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll ans = 0, aa = 0, bb = 0;
  while (k > 0) {
    bool f = 1;
    if (k - a[aa] > 0) {
      ans++;
      k -= a[aa];
      aa++;
      f = 0;
    }
    if (k - b[bb] > 0) {
      ans++;
      k -= b[bb];
      bb++;
      f = 0;
    }
    if (f)
      break;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll MOD = 1000000007;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m];
  vector<ll> A;
  vector<ll> B;
  A.push_back(0);
  B.push_back(0);
  rep(i, n) {
    cin >> a[i];
    A.push_back(A.at(i) + a[i]);
  }
  rep(i, m) {
    cin >> b[i];
    B.push_back(B.at(i) + b[i]);
  }
  ll best = m;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll prc = k - A.at(i);
    if (prc < 0)
      break;
    while (1) {
      if (prc >= B.at(best))
        break;
      best--;
      if (best < 0)
        break;
    }
    ans = max(ans, i + best);
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll MOD = 1000000007;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[n];
  vector<ll> A;
  vector<ll> B;
  A.push_back(0);
  B.push_back(0);
  rep(i, n) {
    cin >> a[i];
    A.push_back(A.at(i) + a[i]);
  }
  rep(i, m) {
    cin >> b[i];
    B.push_back(B.at(i) + b[i]);
  }
  ll best = m;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll prc = k - A.at(i);
    if (prc < 0)
      break;
    while (1) {
      if (prc >= B.at(best))
        break;
      best--;
      if (best < 0)
        break;
    }
    ans = max(ans, i + best);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, k, i, ans = 0;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (i = 1; i < n; i++) {
    a[i] = a[i] + a[i - 1];
  }
  for (i = 1; i < m; i++) {
    b[i] = b[i] + b[i - 1];
  }
  for (i = 0; i < n; i++) {
    if (a[i] > k) {
      break;
    }
    ll read = i + 1;
    ll rem = k - a[i];
    ll ind = upper_bound(all(b), rem) - b.begin();
    if (ind > 0) {
      ind--;
    }
    if (ind != m && b[ind] <= rem) {
      read = read + ind + 1;
    }
    ans = max(ans, read);
  }
  for (i = 0; i < m; i++) {
    if (b[i] <= k) {
      ans = max(ans, i + 1);
    }
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, k, i, ans = 0;
  cin >> n >> m >> k;
  vector<ll> a(n), b(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (i = 1; i < n; i++) {
    a[i] = a[i] + a[i - 1];
  }
  for (i = 1; i < m; i++) {
    b[i] = b[i] + b[i - 1];
  }
  for (i = 0; i < n; i++) {
    if (a[i] > k) {
      break;
    }
    ll read = i + 1;
    ll rem = k - a[i];
    ll ind = upper_bound(all(b), rem) - b.begin();
    ll temp = read;
    if (ind != m && b[ind] <= rem) {
      read = read + ind + 1;
      ans = max(ans, read);
    }
    if (ind > 0) {
      ind--;
    }
    if (b[ind] <= rem) {
      read = temp + ind + 1;
      ans = max(ans, read);
    }
  }
  for (i = 0; i < m; i++) {
    if (b[i] <= k) {
      ans = max(ans, i + 1);
    }
  }
  cout << ans << "\\n";
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 1e9 + 7;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;

  ll a[n + 1], b[m + 1];
  a[0] = 0, b[0] = 0;

  for (int i = 1; i <= n; ++i) {
    int in;
    cin >> in;
    a[i] = a[i - 1] + in;
  }

  for (int i = 1; i <= m; ++i) {
    int in;
    cin >> in;
    b[i] = b[i - 1] + in;
  }

  int ans = 0;
  int j = m;
  for (int i = 0; i <= n && a[i] <= k; ++i) {
    while (a[i] + b[j] > k) {
      --j;
    }

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

  cout << ans << endl;
}

int main(void) {
  int t = 1;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 1e9 + 7;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;

  ll a[n + 1], b[m + 1];
  a[0] = 0, b[0] = 0;

  for (int i = 1; i <= n; ++i) {
    int in;
    cin >> in;
    a[i] = a[i - 1] + in;
  }

  for (int i = 1; i <= m; ++i) {
    int in;
    cin >> in;
    b[i] = b[i - 1] + in;
  }

  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (a[i] > k) {
      break;
    }

    int j = m;
    while (a[i] + b[j] > k) {
      --j;
    }

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

  cout << ans << endl;
}

int main(void) {
  int t = 1;
  while (t--)
    solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <deque>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m], pa[n + 1], pb[m + 1];
  pa[0] = 0;
  pb[0] = 0;
  REP(i, n) {
    cin >> a[i];
    pa[i + 1] = a[i] + pa[i];
  }
  REP(i, m) {
    cin >> b[i];
    pb[i + 1] = b[i] + pb[i];
  }

  ll ans = 0;
  ll checkpoint_b = m;
  REP(i, n + 1) {
    if (pa[i] > k)
      break;
    while (pb[checkpoint_b] > k - pa[i]) {
      checkpoint_b--;
    }
    ans = max(ans, i + checkpoint_b);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <deque>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m], pa[n + 1], pb[m + 1];
  pa[0] = 0;
  pb[0] = 0;
  REP(i, n) {
    cin >> a[i];
    pa[i + 1] = a[i] + pa[i];
  }
  REP(i, m) {
    cin >> b[i];
    pb[i + 1] = b[i] + pb[i];
  }

  ll best_b = m;
  while (1) {
    if (pb[best_b] <= k)
      break;
    best_b--;
  }

  ll ans = best_b;
  REP1(i, n + 1) {
    if (pa[i] > k)
      break;
    int checkpoint_b = best_b;
    while (1) {
      if (pb[checkpoint_b] <= k - pa[i]) {
        ans = max(ans, i + checkpoint_b);
        break;
      }
      checkpoint_b--;
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  ll time = 0;
  ll book_b = 0;
  ll book_a = 0;
  ll books = 0;
  for (ll i = 0; i < n and time + a[i] <= k; i++) {
    time += a[i];
    book_a = i + 1;
  }
  for (ll i = book_a - 1; i >= -1; i--) {
    for (ll j = book_b; j < m and time + b[j] <= k; j++) {
      time += b[j];
      book_b = j + 1;
    }
    books = max(books, book_a + book_b);
    if (book_a != 0) {
      time -= a[i];
      book_a--;
    }
  }
  cout << books << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  ll time = 0;
  ll book_b = 0;
  ll book_a = 0;
  ll books = 0;
  for (ll i = 0; i < n and time + a[i] <= k; i++) {
    time += a[i];
    book_a = i + 1;
  }
  for (ll i = book_a - 1; i >= -1; i--) {
    for (ll j = book_b; j < m and time + b[j] <= k; j++) {
      time += b[j];
      book_b = j + 1;
    }
    books = max(books, book_a + book_b);
    if (book_a != 0) {
      time -= a[i];
      book_a--;
    }
  }
  cout << books << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

Fixed submission:

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  queue<int> a, b;
  rep(i, n) {
    int j;
    cin >> j;
    a.push(j);
  }
  rep(i, m) {
    int j;
    cin >> j;
    b.push(j);
  }

  ll sum = 0;
  rep(i, n + m) {
    int x = a.front(), y = b.front();
    if (x < y) {
      sum += x;
      a.pop();
    } else {
      sum += y;
      b.pop();
    }
    if (sum > k) {
      cout << i << endl;
      return 0;
    }
  }
  cout << n + m << endl;
  return 0;
}