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

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;

class Solution {
public:
  int c(int n, int m, const vector<int> &t1, const vector<int> &t2, int k) {
    int res = 0;

    vector<ll> s1(n + 1, 0), s2(m + 1, 0);
    for (int i = 1; i < n + 1; ++i) {
      s1[i] = s1[i - 1] + t1[i - 1];
    }
    for (int i = 1; i < m + 1; ++i) {
      s2[i] = s2[i - 1] + t2[i - 1];
    }

    ll l = 0, r = n + m;
    while (l <= r) {
      ll mid = (l + r) / 2;

      ll tres = INT64_MAX;
      for (int k1 = 0; k1 <= mid; ++k1) {
        if (k1 > n || mid - k1 > m) {
          continue;
        }
        tres = min(tres, s1[k1] + s2[mid - k1]);
      }
      if (tres <= k) {
        res = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }

    return res;
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> t1(n), t2(m);
  for (int i = 0; i < n; ++i)
    cin >> t1[i];
  for (int i = 0; i < m; ++i)
    cin >> t2[i];
  Solution zhy;
  cout << zhy.c(n, m, t1, t2, k) << endl;
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;

class Solution {
public:
  int c(int n, int m, const vector<int> &t1, const vector<int> &t2, int k) {
    int res = 0;

    vector<ll> s1(n + 1, 0), s2(m + 1, 0);
    for (int i = 1; i < n + 1; ++i) {
      s1[i] = s1[i - 1] + t1[i - 1];
    }
    for (int i = 1; i < m + 1; ++i) {
      s2[i] = s2[i - 1] + t2[i - 1];
    }

    ll l = 0, r = n + m;
    while (l <= r) {
      ll mid = (l + r) / 2;

      ll tres = INT64_MAX;
      for (int k1 = 0; k1 <= mid; ++k1) {
        tres = min(tres, s1[k1] + s2[mid - k1]);
      }
      if (tres <= k) {
        res = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }

    return res;
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> t1(n), t2(m);
  for (int i = 0; i < n; ++i)
    cin >> t1[i];
  for (int i = 0; i < m; ++i)
    cin >> t2[i];
  Solution zhy;
  cout << zhy.c(n, m, t1, t2, k) << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  unsigned long int t = 0;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  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 < m; i++) {
    t = t + b[i];
  }
  int j = m;
  int ans = 0;
  for (int i = 0; i < n + 1; i++) {
    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;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int nibun(int x, int y) { return x <= y; }
int main() {
  int N, M, o, amount, ok, ng, mid, ans;
  unsigned long int K, time;
  cin >> N >> M >> K;
  int n = N;
  int m = M;
  vector<int> a(N);
  vector<int> b(M);
  time = o = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    time += a[i];
    a[i] = time;
    if (o == 0 && K < time) {
      n = i;
      o = 1;
    }
  }
  ans = n;
  time = o = 0;
  for (int i = 0; i < M; i++) {
    cin >> b[i];
    time += b[i];
    b[i] = time;
    if (o == 0 && K < time) {
      m = i;
      o = 1;
    }
  }
  if (ans < m) {
    ans = m;
  }
  time = 0;
  for (int i = 0; i < n; i++) {
    time = K - a[i];
    amount = i + 1;
    ok = -1;
    ng = m;
    while (ng - ok > 1) {
      mid = ok + ng;
      if (nibun(b[mid], time)) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    amount += ok + 1;
    if (ans < amount) {
      ans = amount;
    }
  }
  cout << ans << 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++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001;

int main() {
  int n, m;
  ll 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: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

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

int main() {
  int n, m;
  ll k;
  vector<ll> a(n);
  vector<ll> b(m);
  cin >> n >> m >> k;
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll tot = 0;
  int i = 0;
  int j = 0;
  ll count = 0;
  while (tot < k) {
    if (a[i] < b[j] && i < n) {
      tot += a[i];
      i++;
      count++;
      continue;
    }
    if (a[i] < b[j] && i == n) {
      if (j == m)
        break;
      tot += b[j];
      j++;
      count++;
      continue;
    }
    if (a[i] >= b[j] && j < m) {
      tot += b[j];
      j++;
      count++;
      continue;
    }
    if (a[i] >= b[j] && j == m) {
      if (i == n)
        break;
      tot += a[i];
      i++;
      count++;
      continue;
    }
  }
  if (tot > k)
    count--;
  cout << count << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, M;
  long long int K;
  cin >> N >> M >> K;

  vector<long long int> A(N);
  vector<long long int> B(M);
  vector<long long int> a(N + 1);
  vector<long long int> b(M + 1);
  a.at(0) = 0;
  b.at(0) = 0;
  int i;

  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  int ans = 0;
  for (i = 0; i < N; i++) {
    a.at(i + 1) = a.at(i) + A.at(i);
  }

  for (i = 0; i < M; i++) {
    b.at(i + 1) = b.at(i) + B.at(i);
  }

  int j = M;
  for (i = 0; i < N + 1; i++) {
    if (a.at(i) > K) {
      break;
    }
    while (a.at(i) + b.at(j) > K) {
      j--;
    }
    ans = max(i + j, ans);
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  unsigned int K;
  cin >> N >> M >> K;

  vector<long long int> A(N);
  vector<long long int> B(M);
  vector<long long int> a(N + 1);
  vector<long long int> b(M + 1);
  a.at(0) = 0;
  b.at(0) = 0;
  int i, j;

  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  int max = 0;
  int b_max = 0;

  for (j = 0; j < M; j++) {
    b.at(j + 1) = b.at(j) + B.at(j);
    if (b.at(j + 1) > K) {
      break;
    }
    b_max++;
  }
  max = b_max;

  for (i = 1; i < N + 1; i++) {
    a.at(i) = a.at(i - 1) + A.at(i - 1);
    if (a.at(i) > K) {
      break;
    }
    for (j = b_max; j >= 0; j--) {
      if (a.at(i) + b.at(j) <= K) {
        if (i + j > max) {
          max = i + j;
        }
        break;
      }
    }
  }
  cout << max << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;

#define pb push_back
#define pf pop_front
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(), (x).end()
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

const ll N = 2e5 + 5;
ll a[N], b[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, k;
  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];
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (k >= a[i]) {
      ll r = upper_bound(b + 1, b + 1 + m, k - a[i]) - b - 1;
      ans = max(ans, r + i);
    }
  }
  cout << ans << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;

#define pb push_back
#define pf pop_front
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(), (x).end()
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  deque<ll> 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 cnt = 0, ans = 0;
  while (cnt < a.size() && k >= 0) {
    k -= a[cnt++];
    if (k >= 0)
      ans++;
    else
      k += a[cnt - 1];
  }
  cnt = 0;
  ll cc = a.size() - 1, dd = ans;
  while (cnt < b.size() && k >= 0) {
    if (k - b[cnt] >= 0) {
      cnt++;
      dd++;
      k -= b[cnt];
    } else {
      k += a[cc--];
    }
    ans = max(ans, dd);
  }
  cout << ans << "\\n";
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;

int run_test() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n + 1], b[m + 1];
  a[0] = b[0] = 0;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll t;
    cin >> t;
    sum += t;
    a[i] = sum;
  }
  sum = 0;
  for (int i = 1; i <= m; i++) {
    ll t;
    cin >> t;
    sum += t;
    b[i] = sum;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (k - a[i] >= 0) {
      int j = lower_bound(b, b + m, k - a[i]) - b;
      if (j > m || b[j] > k - a[i]) {
        j--;
      }
      ans = max(ans, i + j);
    }
  }
  cout << ans;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;

int run_test() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll arr[n];
  for (int i = 0; i < m + n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n + m);
  ll ans = 0;
  ll i = 0, count = 0;
  while (i < n + m) {
    ans += arr[i++];
    count++;
    if (ans > k) {
      cout << count - 1;
      return 0;
    }
  }
  cout << count;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1001001001;
// const ll INF = 1000000000000000000;

ll a, b, v, w, t;

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

  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    if (a[i] > k)
      continue;
    while (b[j] > k - a[i])
      j--;
    ans = max(i + j, ans);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

const int INF = 1001001001;
// const ll INF = 1000000000000000000;

ll a, b, v, w, t;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  int fla = n + 1, flb = m + 1;
  rep(i, n + 1) {
    if (i == 0) {
      a[i] = 0;
      continue;
    }
    ll tmp;
    cin >> tmp;
    a[i] = a[i - 1] + tmp;
    if (a[i] > k)
      fla = i;
  }
  rep(i, m + 1) {
    if (i == 0) {
      b[i] = 0;
      continue;
    }
    ll tmp;
    cin >> tmp;
    b[i] = b[i - 1] + tmp;
    if (b[i] > k)
      flb = i;
  }

  int ans = 0;
  rep(i, fla) {
    if (a[i] > k)
      continue;
    rep(j, flb) {
      ll tmp = a[i] + b[j];
      if (tmp <= k) {
        ans = max(i + j, ans);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int ans;
int n, m, k;
int a[200010], b[200010];
long long psa[200010], psb[200010];

int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    psa[i] = a[i] + psa[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    psb[i] = b[i] + psb[i - 1];
  }
  int t = m;
  for (int i = 0; i <= n; i++) {
    int cnt;
    if (k >= psa[i]) {
      cnt = i;
      for (int j = t; j >= 0; j--) {
        if (psb[j] <= k - psa[i]) {
          cnt = i + j;
          ans = max(cnt, ans);
          t = j;
          break;
        }
      }
    } else
      break;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

int ans;
int n, m, k;
int a[200010], b[200010];
long long psa[200010], psb[200010];

int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    psa[i] = a[i] + psa[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    psb[i] = b[i] + psb[i - 1];
  }
  int t = m;
  for (int i = 0; i <= n; i++) {
    int cnt;
    if (k >= psa[i]) {
      cnt = i;
      for (int j = 0; j <= t; j++) {
        if (psb[j] <= k - psa[i]) {
          cnt = i + j;
          ans = max(cnt, ans);
        } else {
          t = j;
          break;
        }
      }
    } else
      break;
  }
  printf("%d\\n", ans);
  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 < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;

int main() {
  int N = 0, M = 0;
  ll K;
  cin >> N >> M >> K;
  vector<ll> A(N + 1, 0);
  vector<ll> B(M + 1, 0);

  REP1(i, N) {
    cin >> A.at(i);
    A.at(i) += A.at(i - 1);
  }
  REP1(i, M) {
    cin >> B.at(i);
    B.at(i) += B.at(i - 1);
  }

  ll imax = 0;
  int i = 0, ans = 0;

  REP(count, N + 1) {
    if (A.at(count) > K) {
      i = count - 1;
      break;
    }
    i = count;
  }
  imax = A.at(i);

  int j = 0;
  for (i; i != -1; i--) {
    imax = A.at(i);
    FOR(count, j, M + 1) {
      if (imax + B.at(count) > K) {
        j = count - 1;
        break;
      }
      j = count;
      ans = max(ans, i + j);
    }
  }

  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 REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;

int main() {
  int N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> B(M);

  REP(i, N) cin >> A.at(i);
  REP(i, M) cin >> B.at(i);

  ll temp = 0;
  int i = 0, ans = 0;
  while (temp < K && i < N) {
    temp += A.at(i);
    i++;
  }

  if (i != 0 && temp > K) {
    temp -= A.at(i - 1);
    i--;
  }

  int j = 0;
  while (i >= 0) {
    j = 0;
    while (temp < K) {
      temp += B.at(j);
      j++;
    }

    if (j != 0 && temp > K) {
      temp -= B.at(j - 1);
      j--;
    }

    if (ans < i + j)
      ans = i + j;

    if (i != 0)
      temp -= A.at(i - 1);
    i--;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m];
  for (ll i = 0; i < n; ++i)
    cin >> a[i];
  for (ll j = 0; j < m; ++j)
    cin >> b[j];
  ll asum[n + 1], bsum[m + 1];
  asum[0] = 0, bsum[0] = 0;
  for (ll i = 0; i < n; ++i)
    asum[i + 1] = asum[i] + a[i];
  for (ll i = 0; i < m; ++i)
    bsum[i + 1] = bsum[i] + b[i];
  ll cnt = 0;
  ll j = m;
  for (ll i = 0; i < n + 1; ++i) {
    // if(asum[i]==0 || bsum[j]==0) break;
    if (asum[i] > k)
      break;
    while (bsum[j] > k - asum[i])
      --j;
    // while(asum[i]+bsum[j]>k){
    // cout<<asum[i]<<" "<<bsum[j]<<'\\n';
    // cout<<asum[i]<<" "<<bsum[j]<<'\\n';
    cnt = max(cnt, i + j);
    // cout<<i<<" "<<j<<'\\n';
  }
  cout << cnt;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m];
  for (ll i = 0; i < n; ++i)
    cin >> a[i];
  for (ll j = 0; j < m; ++j)
    cin >> b[j];
  ll asum[n + 1], bsum[m + 1];
  asum[0] = 0, bsum[0] = 0;
  for (ll i = 0; i < n; ++i)
    asum[i + 1] = asum[i] + a[i];
  for (ll i = 0; i < m; ++i)
    bsum[i + 1] = bsum[i] + b[i];
  ll cnt = 0;
  ll i = n + 1;
  for (ll j = 1; j <= m; ++j) {
    // if(asum[i]==0 || bsum[j]==0) break;
    if (bsum[j] <= k) {
      while (asum[i] + bsum[j] >= k) {
        // cout<<asum[i]<<" "<<bsum[j]<<'\\n';
        --i;
      }
      // cout<<asum[i]<<" "<<bsum[j]<<'\\n';
      cnt = max(cnt, i + j);
      // cout<<i<<" "<<j<<'\\n';
    }
  }
  cout << cnt;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

string s, t;
ll a[200005], b[200005], pa[200005], pbb[200005];

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n, m, x, i;
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    cin >> n >> m >> x;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      pa[i + 1] = pa[i] + a[i];
    }
    for (i = 0; i < m; i++) {
      cin >> b[i];
      pbb[i + 1] = pbb[i] + b[i];
    }
    int ans = 0;
    for (i = 0; i <= n; i++) {
      if (pa[i] <= x)
        ans = max(
            ans, i + (int)(upper_bound(pbb, pbb + m + 1, x - pa[i]) - pbb - 1));
      else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

string s, t;
ll a[100500], b[100500], pa[100500], pbb[100500];

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n, m, x, i;
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    cin >> n >> m >> x;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      pa[i + 1] = pa[i] + a[i];
    }
    for (i = 0; i < m; i++) {
      cin >> b[i];
      pbb[i + 1] = pbb[i] + b[i];
    }
    int ans = 0;
    for (i = 0; i <= n; i++) {
      if (pa[i] <= x)
        ans = max(
            ans, i + (int)(upper_bound(pbb, pbb + m + 1, x - pa[i]) - pbb - 1));
      else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}