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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n);
  vector<long> b(m);
  for (long i = 0; i < n; i++)
    cin >> a[i];
  for (long i = 0; i < m; i++)
    cin >> b[i];
  long total = 0;
  long c = 0;
  long cnt = 0;
  while (true) {
    if (total + a[c] <= k) {
      total += a[c];
      c++;
      cnt++;
      if (c == n)
        break;
    } else
      break;
  }
  long A = cnt;
  long e = 0;
  while (true) {
    if (total + b[e] <= k) {
      total += b[e];
      e++;
      cnt++;
      if (e == m)
        break;
    } else
      break;
  }
  long B = cnt - A;
  long ans = cnt;
  for (int i = 0; i < A; i++) {
    total -= a[A - 1 - i];
    cnt--;
    while (true) {
      if (B == m)
        break;
      if (total + b[B] <= k) {
        total += b[B];
        B++;
        cnt++;
      } else
        break;
    }
    if (cnt > ans)
      ans = cnt;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n);
  vector<long> b(m);
  for (long i = 0; i < n; i++)
    cin >> a[i];
  for (long i = 0; i < m; i++)
    cin >> b[i];
  long total = 0;
  long c = 0;
  long cnt = 0;
  while (true) {
    if (total + a[c] <= k) {
      total += a[c];
      c++;
      cnt++;
      if (c == n)
        break;
    } else
      break;
  }
  long A = cnt;
  long e = 0;
  while (true) {
    if (total + b[e] <= k) {
      total += b[e];
      e++;
      cnt++;
      if (e == m)
        break;
    } else
      break;
  }
  long B = cnt - A;
  long ans = cnt;
  for (int i = 0; i < A; i++) {
    total -= a[A - 1 - i];
    cnt--;
    while (true) {
      if (total + b[B] <= k) {
        total += b[B];
        B++;
        cnt++;
      } else
        break;
    }
    if (cnt > ans)
      ans = cnt;
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define endl "\\n"
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\\n"
#define rep(i, n) for (i = 0; i < (n); i++)
#define rrep(i, n) for (i = (n - 1); i >= 0; i--)
using namespace std;

bool vis[200005] = {0};
void solve1();
void solve() {
  int t;
  cin >> t;
  while (t--) {
    solve1();
  }
}
signed main() {
  solve1();
  return 0;
}
void solve1() {
  int n, m, k;
  cin >> n >> m >> k;
  int arr[n], brr[m];
  int a = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] += a;
    a = arr[i];
  }
  a = 0;
  for (int i = 0; i < m; i++) {
    cin >> brr[i];
    brr[i] += a;
    a = brr[i];
  }
  int i = 0, j = 0, ans = 0;
  while (arr[i] <= k && i < n) {
    ans++;
    i++;
  }
  i--;
  while (brr[j] <= k && j < m && i >= 0) {
    if (arr[i] + brr[j] <= k) {
      ans = max(ans, i + j + 2);
      j++;
    } else {
      i--;
    }
  }
  int ans2 = 0;
  j = 0;
  while (brr[j] <= k && j < m) {
    ans2++;
    j++;
  }
  ans = max(ans, ans2);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define endl "\\n"
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\\n"
#define rep(i, n) for (i = 0; i < (n); i++)
#define rrep(i, n) for (i = (n - 1); i >= 0; i--)
using namespace std;

bool vis[200005] = {0};
void solve1();
void solve() {
  int t;
  cin >> t;
  while (t--) {
    solve1();
  }
}
signed main() {
  solve1();
  return 0;
}
void solve1() {
  int n, m, k;
  cin >> n >> m >> k;
  int arr[n], brr[m];
  int a = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] += a;
    a = arr[i];
  }
  a = 0;
  for (int i = 0; i < m; i++) {
    cin >> brr[i];
    brr[i] += a;
    a = brr[i];
  }
  int i = 0, j = 0, ans = 0;
  while (arr[i] <= k && i < n) {
    ans++;
    i++;
  }
  i--;
  while (brr[j] <= k && j < m && i >= 0) {
    if (arr[i] + brr[j] <= k) {
      ans = max(ans, i + j + 2);
      j++;
    } else {
      i--;
    }
  }
  int ans2 = 0;
  j = 0;
  while (brr[j] <= k) {
    ans2++;
  }
  ans = max(ans, ans2);
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

ll dp[201010][2];
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};

// long longしか使わない
// 素数は1より大きい
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]; }
  rep(i, n - 1) { a[i + 1] += a[i]; }
  rep(i, m - 1) { b[i + 1] += b[i]; }
  ll ans = 0;
  ll left1 = -1;
  ll right1 = m;
  while (right1 - left1 > 1) {
    ll mid1 = (left1 + right1) / 2;
    if (b[mid1] <= k)
      left1 = mid1;
    else {
      right1 = mid1;
    }
  }
  ans = max(right1, ans);
  rep(i, n) {
    if (a[i] > k)
      break;
    ll res = i + 1;
    ll res2 = k - a[i];
    ll left = -1;
    ll right = m;
    while (right - left > 1) {
      ll mid = (left + right) / 2;
      if (b[mid] <= res2)
        left = mid;
      else {
        right = mid;
      }
    }
    ans = max(right + res, ans);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

ll dp[101010][110];
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};

// long longしか使わない
// 素数は1より大きい
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;
  while (1) {
    if (a[0] <= b[0]) {
      k -= a[0];
      a.erase(a.begin());
    } else {
      k -= b[0];
      b.erase(b.begin());
    }
    if (ans == n + m)
      break;
    if (k <= 0)
      break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long long int n, m, k, max = 0, k1, l, q;
  cin >> n >> m >> k;

  vector<long long int> a(n, 0);
  vector<long long int> b(m, 0);

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

  if (k < a[0] && k < b[0]) {
    cout << "0\\n";
    return 0;
  }

  for (int i = 0; i <= n; i++) {
    k1 = k;
    if (i == 0) {
      for (int p = 1; p <= m; p++) {
        k1 = k1 - b[p - 1];
        if (k1 < 0) {
          l = p;
          q = k - k1;
          if (p - 1 >= max) {
            max = p - 1;
          }
          break;
        }
        if (p == m) {
          l = p;
          q = k - k1;
          if (p >= max) {
            max = p;
          }
          break;
        }
      }
    } else {
      k = k - a[i - 1];
      if (k < 0) {
        if (i - 1 >= max) {
          max = i - 1;
        }
        break;
      }
      k1 = k - q;
      for (int p = l; p >= 0; p--) {
        if (p == m && k1 >= 0) {
          if (p + i >= max) {
            max = p + i;
          }
          break;
        }
        k1 = k1 + b[p - 1];
        q -= b[p - 1];
        if (k1 >= 0) {
          l = p;
          q += b[p - 1];
          if (p + i - 1 >= max) {
            max = p + i - 1;
          }
          break;
        }
      }
    }
  }

  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  long long int n, m, k, max = 0, k1;
  cin >> n >> m >> k;

  vector<long long int> a(n, 0);
  vector<long long int> b(m, 0);

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

  if (k < a[0] && k < b[0]) {
    cout << "0\\n";
    return 0;
  }

  for (int i = 0; i <= n; i++) {
    k1 = k;
    if (i == 0) {
      for (int p = 1; p <= m; p++) {
        k1 = k1 - b[p - 1];
        if (k1 < 0) {
          if (p - 1 >= max) {
            max = p - 1;
          }
          break;
        }
        if (p == m) {
          if (p >= max) {
            max = p;
          }
          break;
        }
      }
    } else {
      k = k - a[i - 1];
      if (k < 0) {
        if (i - 1 >= max) {
          max = i - 1;
        }
        break;
      }
      k1 = k;
      for (int p = 1; p <= m; p++) {
        k1 = k1 - b[p - 1];
        if (k1 < 0) {
          if (p - 1 + i >= max) {
            max = p - 1 + i;
          }
          break;
        }
        if (p == m) {
          if (p + i >= max) {
            max = p + i;
          }
          break;
        }
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

ll Atot[201010], Btot[201010];

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

  rep(i, n) {
    ll a;
    cin >> a;
    Atot[i + 1] = Atot[i] + a;
  }
  rep(i, m) {
    ll b;
    cin >> b;
    Btot[i + 1] = Btot[i] + b;
  }

  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    if (Atot[i] > k)
      break;

    while (Atot[i] + Btot[j] > k)
      j--;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    if (sa[i] > k)
      break;

    while (sa[i] + sb[j] > k)
      j--;
    ans = max(ans, i + j);
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

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

  /*
  rep(i,n) cout<<sa[i]<<" ";
  cout<<endl;
  rep(i,m) cout<<sb[i]<<" ";
  cout<<endl;*/

  int ans = 0;
  int id = m;
  rep(i, n + 1) {
    while (id >= 0 && sa[i] + sb[id] > k) {
      id--;
    }

    if (id < 0)
      break;
    ans = max(ans, i + id);
  }

  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

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

  int ans = 0;
  int id = m - 1;
  rep(i, n) {
    while (i >= 0 && sa[i] + sb[id] > k) {
      id--;
    }

    if (sa[i] + sb[id] <= k)
      ans = max(ans, i + 1 + id + 1);
  }

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

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

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];

  vector<ll> sumA(N + 1, 0), sumB(M + 1, 0);
  for (int i = 1; i <= N; i++) {
    sumA[i] = sumA[i - 1] + a[i - 1];
  }
  for (int i = 1; i <= M; i++) {
    sumB[i] = sumB[i - 1] + b[i - 1];
  }
  ll ans = 0;
  rep(i, N + 1) {
    if (sumA[i] > K)
      break;
    int last = K - sumA[i];
    auto itr = upper_bound(all(sumB), last);
    ans = max(ans, (ll)(i + itr - sumB.begin() - 1));
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, ans = 0;
  ll k, sum = 0;
  cin >> n >> m >> k;
  queue<int> a;
  queue<int> b;
  rep(i, 0, n) {
    int ai;
    cin >> ai;
    a.push(ai);
  }
  rep(i, 0, m) {
    int bi;
    cin >> bi;
    b.push(bi);
  }
  while (true) {
    if (sum + min(a.front(), b.front()) > k || (a.empty() && b.empty())) {
      cout << ans << endl;
      return 0;
    }
    if (a.empty() || a.front() >= b.front()) {
      sum += b.front();
      b.pop();
    } else {
      sum += a.front();
      a.pop();
    }
    ans++;
  }
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

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

  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int j = 0; j < m; j++)
    cin >> b[j];
  vector<long long> prefix_a(n + 1), prefix_b(m + 1);
  prefix_a[1] = a[0];
  prefix_b[1] = b[0];
  for (int i = 1; i < n; i++)
    prefix_a[i + 1] = prefix_a[i] + a[i];

  for (int i = 1; i < m; i++)
    prefix_b[i + 1] = prefix_b[i] + b[i];

  int ans = 0;
  prefix_a[0] = 0;
  for (int i = 0, j = m; i <= n; i++) {
    if (prefix_a[i] > k)
      break;
    while (prefix_a[i] + prefix_b[j] > k)
      j--;
    ans = max(i + j, ans);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

long long find(vector<long long> &a, vector<long long> &b, int i, int j, int n,
               int m, vector<vector<long long>> &dp, long long k) {
  if (i >= n || j >= m)
    return 0;

  if (i >= n && j >= m && (k >= 0 || k < 0))
    return 0;
  if (k < 0)
    return 0;

  if (dp[i][j] != -1)
    return dp[i][j];

  long long ans1 = 0, ans2 = 0;

  if (i < n && (k - a[i]) >= 0)
    ans1 = 1 + find(a, b, i + 1, j, n, m, dp, k - a[i]);
  if (j < m && (k - b[j]) >= 0)
    ans2 = 1 + find(a, b, i, j + 1, n, m, dp, k - b[j]);

  dp[i][j] = max(ans1, ans2);

  return dp[i][j];
}

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

  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int j = 0; j < m; j++)
    cin >> b[j];
  int i = 0, j = 0;
  long long ans = 0;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, -1));

  cout << find(a, b, 0, 0, n, m, dp, k) << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\\n';
const int MX = 100001; // check the limits, dummy

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

  int N, M;
  cin >> N >> M;

  ll K;
  cin >> K;
  ll A[N], B[M];
  F0R(i, N) cin >> A[i];
  F0R(i, M) cin >> B[i];

  ll as = 0;
  F0R(i, N) as += A[i];
  ll bs = 0;
  int bp = 0;
  int ans = 0;
  F0Rd(i, N + 1) {
    if (i < N)
      as -= A[i];
    if (as <= K) {
      while (bp < M && as + bs + B[bp] <= K) {
        bs += B[bp];
        bp++;
      }
      ckmax(ans, i + bp);
    }
    //        cout << as << " " << bs << " " << bp << nl;
  }
  cout << ans << nl;

  return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)

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

  ll *a = new ll[n];
  ll *b = new ll[m];
  rep(i, 0, n - 1) { cin >> a[i]; }
  rep(i, 0, m - 1) { cin >> b[i]; }

  ll as = 0;
  ll bs = 0;
  ll bp = 0;
  ll ans = 0;
  rep(i, 0, n - 1) { as += a[i]; }
  repr(i, n, 0) {
    if (i < n) {
      as -= a[i];
    }
    // as -= a[i];
    if (as <= k) {
      while (bp < m && (as + bs <= k)) {
        bs += b[i];
        bp++;
      }
      ans = max(ans, bp + i);
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)

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

  ll *a = new ll[n];
  ll *b = new ll[m];
  rep(i, 0, n - 1) { cin >> a[i]; }
  rep(i, 0, m - 1) { cin >> b[i]; }

  ll as = 0;
  ll bs = 0;
  ll bp = 0;
  ll ans = 0;
  rep(i, 0, n - 1) { as += a[i]; }
  repr(i, n, 0) {
    if (i < n) {
      as -= a[i];
    }
    // as -= a[i];
    if (as <= k) {
      while (bp < m && (as + bs + b[bp] <= k)) {
        bs += b[bp];
        bp++;
      }
      ans = max(ans, bp + i);
    }
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)

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

  ll *a = new ll[n];
  ll *b = new ll[m];
  rep(i, 0, n - 1) { cin >> a[i]; }
  rep(i, 0, m - 1) { cin >> b[i]; }

  ll as = 0;
  ll bs = 0;
  ll bp = 0;
  ll ans = 0;
  rep(i, 0, n - 1) { as += a[i]; }
  repr(i, n, 0) {
    if (i < n) {
      as -= a[i];
    }
    // as -= a[i];
    if (as <= k) {
      while (bp < m && (as + bs <= k)) {
        bs += b[i];
        bp++;
      }
      ans = max(ans, bp + i);
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double PI = acos(-1);
const int M = 998244353;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define oo 1e16

int main() {
  //	freopen("input.txt","r",stdin);
  //	freopen("output.txt","w",stdout);

  int n, m, k;
  cin >> n >> m >> k;
  vi a(n);
  vi b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  int depth = 0;
  for (int i = 0; i < n; ++i) {
    if (k - a[i] >= 0) {
      depth++;
      k -= a[i];
    } else {
      break;
    }
  }
  int mxdepth = 0;
  int j = 0;
  for (int i = depth; i >= 0; i--) {
    while (k - b[j] >= 0) {
      if (j == m)
        break;
      k -= b[j];
      j++;
    }
    mxdepth = max(mxdepth, (i + j));
    if (i == 0)
      break;
    else {
      k += a[i - 1];
      // printf("k+=%d\\n",a[i-1] );
    }
  }
  printf("%d\\n", mxdepth);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double PI = acos(-1);
const int M = 998244353;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define oo 1e16

int main() {
  //	freopen("input.txt","r",stdin);
  //	freopen("output.txt","w",stdout);

  int n, m, k;
  cin >> n >> m >> k;
  vi a(n);
  vi b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  int depth = 0;
  for (int i = 0; i < n; ++i) {
    if (k - a[i] >= 0) {
      depth++;
      k -= a[i];
    } else {
      break;
    }
  }
  int mxdepth = 0;
  int j = 0;
  for (int i = depth; ~i; --i) {
    while (k - b[j] >= 0) {
      k -= b[j];
      j++;
    }
    mxdepth = max(mxdepth, i + j);
    if (i == 0)
      break;
    k += a[i - 1];
  }
  printf("%d\\n", mxdepth);

  return 0;
}