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

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (ll i = 0; i < m; i++) {
    cin >> b.at(i);
  }

  ll cnt = -1, dnt = n;
  vector<ll> d(n + 1);
  for (ll i = 1; i <= n; i++) {
    d.at(i) += d.at(i - 1);
    d.at(i) += a.at(i - 1);
    if (d.at(i) > k) {
      dnt = i - 1;
      break;
    }
  }

  ll ent = m;
  vector<ll> e(m + 1);
  for (ll i = 1; i <= m; i++) {
    e.at(i) += e.at(i - 1);
    e.at(i) += b.at(i - 1);
    if (e.at(i) > k) {
      ent = i - 1;
      break;
    }
  }

  for (ll i = 0; i <= dnt; i++) {
    for (ll j = ent; j >= 0; j--) {
      if (d.at(i) + e.at(j) <= k) {
        cnt = max(i + j, cnt);
        ent = j;
        break;
      }
    }
  }
  if (cnt == -1)
    cnt = dnt + ent;

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (ll i = 0; i < m; i++) {
    cin >> b.at(i);
  }

  ll cnt = -1, dnt = n;
  vector<ll> d(n + 1);
  for (ll i = 1; i <= n; i++) {
    d.at(i) += d.at(i - 1);
    d.at(i) += a.at(i - 1);
    if (d.at(i) > k) {
      dnt = i - 1;
      break;
    }
  }

  ll ent = m;
  vector<ll> e(m + 1);
  for (ll i = 1; i <= m; i++) {
    e.at(i) += e.at(i - 1);
    e.at(i) += b.at(i - 1);
    if (e.at(i) > k) {
      ent = i - 1;
      break;
    }
  }

  for (ll i = dnt; i >= 0; i--) {
    for (ll j = ent; j >= 0; j--) {
      if (d.at(i) + e.at(j) <= k) {
        cnt = max(i + j, cnt);
        break;
      }
    }
  }
  if (cnt == -1)
    cnt = dnt + ent;

  cout << cnt << endl;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  unsigned long long k;
  unsigned long long a[200001], b[200001];

  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];
  }
  int mm = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = mm - i; j <= m; j++) {
      if (a[i] + b[j] <= k) {
        mm = max(mm, i + j);
      } else {
        break;
      }
    }
  }
  cout << mm << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  unsigned long long k;
  unsigned long long a[200001], b[200001];

  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];
  }
  int mm = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = mm - i; j <= m; j++) {
      if (a[i] + b[j] <= k) {
        mm = max(mm, i + j);
      } else {
        continue;
      }
    }
  }
  cout << mm << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t n, m, k, ans = 0;
  cin >> n >> m >> k;
  vector<int64_t> a(n + 1), b(m + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> b[i];
  }
  partial_sum(begin(a), end(a), begin(a));
  partial_sum(begin(b), end(b), begin(b));
  for (int64_t i = 0; i < n + 1; i++) {
    int64_t l = k - a[i];
    if (l < 0)
      break;
    int64_t j = upper_bound(begin(b), end(b), l) - begin(b) - 1;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int64_t n, m, k, ans = 0;
  cin >> n >> m >> k;
  vector<int64_t> a(n + 1), b(m + 1);
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(m + 1));
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> b[i];
  }
  dp[0][0] = 0;
  for (int64_t i = 0; i < n + 1; i++) {
    for (int64_t j = 0; j < m + 1; j++) {
      if (i != n)
        dp[i + 1][j] = dp[i][j] + a[i + 1];
      if (j != m)
        dp[i][j + 1] = dp[i][j] + b[j + 1];
      if (dp[i][j] > k)
        break;
      ans = max(ans, i + j);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

  vector<int> a(n);
  vector<int> b(m);

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

  vector<ll> c(n + 1);
  vector<ll> d(m + 1);

  c.at(0) = 0;
  for (int i = 1; i <= n; i++) {
    c.at(i) = c.at(i - 1) + a.at(i - 1);
  }

  // cout << " ddddddddddddddddddddddddddddddddddddddd" << endl;

  d.at(0) = 0;
  for (int i = 1; i <= m; i++) {
    d.at(i) = d.at(i - 1) + b.at(i - 1);
  }

  ll temp;
  int count = d.size() - 1;
  int ans = 0;

  for (int i = 0; i <= n; i++) {
    temp = k - c.at(i);
    if (temp < 0) {
      break;
    }
    while (temp < d.at(count)) {
      count--;
    }
    if (ans < i + count) {
      ans = i + count;
    }
  }

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


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 4)


Fixed submission:

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

  vector<int> a(n);
  vector<int> b(m);

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

  vector<ll> c(n);
  vector<ll> d(m);

  c.at(0) = a.at(0);
  for (int i = 1; i < n; i++) {
    c.at(i) = c.at(i - 1) + a.at(i);
  }

  // cout << " ddddddddddddddddddddddddddddddddddddddd" << endl;

  d.at(0) = b.at(0);
  for (int i = 1; i < m; i++) {
    d.at(i) = d.at(i - 1) + b.at(i);
  }

  ll temp;
  int count = d.size() - 1;
  int ans = 0;

  for (int i = 0; i < n; i++) {
    temp = k - c.at(i);
    while (temp < d.at(count)) {
      count--;
    }
    if (ans < i + count + 2) {
      ans = i + count + 2;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
long long a[200001], b[200001];
int main() {
  a[0] = 0;
  long long n, m, k;
  cin >> n >> m >> k;
  int T = n;
  long long t = 1, l = 1, cnt1 = 0, cnt2 = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
    if (a[i] > k)
      T = i - 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int place = m;
  for (int i = 0; i <= T; i++) {
    long long k2 = k - a[i];
    for (int j = place; j >= 0; j--) {
      // cout<<"i:"<<i<<" j:"<<j<<" place:"<<place<<" k2:"<<k2<<"
      // ans:"<<ans<<endl;
      if (b[j] <= k2) {
        ans = max((long long)i + j, ans), place = j;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[200001], b[200001];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int t = 1, l = 1, cnt1 = 0, cnt2 = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i];
  for (int i = 1; i <= n + m; i++) {
    if (a[t] < b[l]) {
      ans += (long long)a[t];
      t++;
    } else {
      ans += (long long)b[l];
      l++;
    }
    if (ans > (long long)k)
      break;
    cnt1++;
  }
  ans = 0;
  t = 1;
  l = 1;
  for (int i = 1; i <= n + m; i++) {
    if (a[t] <= b[l]) {
      ans += (long long)a[t];
      t++;
    } else {
      ans += (long long)b[l];
      l++;
    }
    if (ans > (long long)k)
      break;
    cnt2++;
  }
  cout << min(cnt1, cnt2);
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
vector<int64_t> vec1;
vector<int64_t> vec2;
int64_t N, M, K;

int main() {
  cin >> N >> M >> K;
  vec1.resize(N + 1);
  vec2.resize(M + 1);
  int64_t n_sum = 0;
  for (int64_t i = 0; i < N; i++) {
    int64_t n;
    cin >> n;
    vec1[i] = n_sum;
    n_sum += n;
  }

  vec1[N] = n_sum;
  int64_t m_sum = 0;
  for (int64_t i = 0; i < M; i++) {
    int64_t m;
    cin >> m;
    vec2[i] = m_sum;
    m_sum += m;
  }

  vec2[M] = m_sum;

  int64_t ans = 0;
  int64_t j = M;
  for (int i = 0; i <= N; i++) {
    if (vec1[i] > K) {
      break;
    }

    while (vec2[j] > (K - vec1[i])) {
      j--;
    }

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
vector<int64_t> vec1;
vector<int64_t> vec2;
int64_t N, M, K;

int64_t dfs(int64_t n_nokori, int64_t m_nokori, int64_t k_nokori,
            int64_t sassuu) {
  if (n_nokori == 0 && m_nokori == 0) {
    return sassuu;
  }

  if (k_nokori <= 0) {
    return sassuu;
  }

  int64_t n_time = vec1[N - n_nokori];
  int64_t m_time = vec2[M - m_nokori];
  int64_t sassuu_n = sassuu;
  int64_t sassuu_m = sassuu;

  if (n_time > k_nokori && m_time > k_nokori) {
    return sassuu;
  }

  if (n_nokori > 0 && k_nokori >= n_time) {
    sassuu_n = dfs(n_nokori - 1, m_nokori, k_nokori - n_time, sassuu + 1);
  }

  if (m_nokori > 0 && k_nokori >= m_time) {
    sassuu_m = dfs(n_nokori, m_nokori - 1, k_nokori - m_time, sassuu + 1);
  }

  return max(sassuu_n, sassuu_m);
}

int main() {
  cin >> N >> M >> K;
  vec1.resize(N);
  vec2.resize(M);
  for (int64_t i = 0; i < N; i++) {
    cin >> vec1.at(i);
  }

  for (int64_t i = 0; i < M; i++) {
    cin >> vec2.at(i);
  }

  int64_t sum = dfs(N, M, K, 0);
  cout << sum << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

long long ans, j, i, a, b, k, arr1[2000000], arr2[2000000], sum1, sum2, jumlah,
    best;
int main() {
  cin >> a >> b >> k;
  for (i = 1; i <= a; i++) {
    cin >> arr1[i];
  }
  for (i = 1; i <= b; i++) {
    cin >> arr2[i];
    sum2 += arr2[i];
    jumlah = sum2;
  }
  best = b;
  sum2 = jumlah;
  for (i = 0; i <= a; i++) {
    // sum2 = jumlah;
    sum1 += arr1[i];
    if (sum1 > k)
      break;

    for (j = best; j >= 0; j--) {
      if (sum2 > k - sum1) {
        sum2 -= arr2[j];

      } else {
        best = j;
        ans = max(ans, i + j);
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

long long ans, j, i, a, b, k, arr1[2000000], arr2[2000000], sum1, sum2, jumlah;
int main() {
  cin >> a >> b >> k;
  for (i = 1; i <= a; i++) {
    cin >> arr1[i];
  }
  for (i = 1; i <= b; i++) {
    cin >> arr2[i];
    sum2 += arr2[i];
    jumlah = sum2;
  }

  for (i = 0; i <= a; i++) {
    sum2 = jumlah;
    sum1 += arr1[i];
    if (sum1 > k)
      break;

    for (j = b; j >= 0; j--) {
      if (sum2 > k - sum1) {
        sum2 -= arr2[j];

      } else {
        ans = max(ans, i + j);
        break;
      }
    }
  }

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long

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

  vector<ll> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    cin >> a[i];
  for (int i = 1; i < n + 1; i++)
    a[i] = a[i - 1] + a[i];
  for (int i = 1; i < m + 1; i++)
    cin >> b[i];
  for (int i = 1; i < m + 1; i++)
    b[i] = b[i - 1] + b[i];

  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    if (a[i] > k)
      break;
    while (b[j] > k - a[i] && j >= 1) {
      j--;
    }
    ans = max(ans, (i + j));
  }

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

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long

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

  vector<ll> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    cin >> a[i];
  for (int i = 1; i < n + 1; i++)
    a[i] = a[i - 1] + a[i];
  for (int i = 1; i < m + 1; i++)
    cin >> b[i];
  for (int i = 1; i < m + 1; i++)
    b[i] = b[i - 1] + a[i];

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

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

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

using ll = long long;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<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];
  vector<ll> sum_a(N + 1), sum_b(M + 1);
  for (int i = 0; i < N; ++i)
    sum_a[i + 1] = sum_a[i] + A[i];
  for (int i = 0; i < M; ++i)
    sum_b[i + 1] = sum_b[i] + B[i];
  // DUMP(sum_a, sum_b);

  ll ans = 0;
  int j = M;
  for (int i = 0; i <= N; ++i) {
    while (j > 0 && sum_a[i] + sum_b[j] > K)
      --j;
    if (j == 0) {
      if (sum_a[i] > K)
        continue;
    }
    // DUMP(i, j);
    ans = max(ans, (ll)(i + j));
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

using ll = long long;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(m), b(m);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < m; ++i)
    cin >> b[i];
  vector<ll> sum_b(m + 2);
  sum_b[0] = 0;
  for (int i = 0; i < m; ++i)
    sum_b[i + 1] = sum_b[i] + b[i];
  sum_b[m + 1] = 1e16;
  // // DUMP(a, b);
  // // DUMP(sum_b);

  ll ans = 0, sum_a = 0;
  for (int i = 0; i < n; ++i) {
    sum_a += a[i];
    if (k - sum_a < 0)
      continue;
    else if (k - sum_a == 0) {
      ans = max(ans, (ll)(i + 1));
      continue;
    }
    int ub =
        i + upper_bound(sum_b.begin(), sum_b.end(), k - sum_a) - sum_b.begin();
    // DUMP(ub);
    ans = max(ans, (ll)ub);
  }

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

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

int main(void) {
  ll N, M, K;
  ll A[200005], B[200005];
  cin >> N >> M >> K;
  rep(i, N) { cin >> A[i]; }
  rep(i, M) { cin >> B[i]; }

  ll A_t[200005], B_t[200005];
  rep(i, N) { A_t[i + 1] = A_t[i] + A[i]; }
  rep(i, M) { B_t[i + 1] = B_t[i] + B[i]; }

  ll best = M;
  ll count;
  ll ans = 0;
  rep(i, N + 1) {
    for (int j = best; j >= 0; j--) {
      if (B_t[j] <= K - A_t[i]) {
        count = i + j;
        if (count > ans) {
          ans = count;
        }
        best = j;
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main(void) {
  ll N, M, K;
  ll A[200000], B[200000];
  cin >> N >> M >> K;
  rep(i, N) { cin >> A[i]; }
  rep(i, M) { cin >> B[i]; }

  ll A_t[200000], B_t[200000];
  rep(i, N) {
    for (int j = i; j < N; j++) {
      A_t[j] += A[i];
    }
  }
  rep(i, M) {
    for (int j = i; j < M; j++) {
      B_t[j] += B[i];
    }
  }

  ll ans = 0;
  ll a_max = 0;
  rep(i, N) {
    if (A_t[i] <= K) {
      a_max = i + 1;
      if (a_max > ans) {
        ans = a_max;
      }
    } else {
      break;
    }
  }
  rep(i, a_max) {
    rep(j, M) {
      if (A_t[a_max - 1 - i] + B_t[j] <= K) {
        ll count = a_max - i + j + 1;
        if (count > ans) {
          ans = count;
        }
      } else {
        break;
      }
    }
  }

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

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int a[maxr], b[maxr];
int32_t main() {
  GO;
  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 = 1; i < n; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m; i++)
    b[i] += b[i - 1];

  int ans = 0;
  for (int i = -1; i < n; i++) {
    if (a[i] > k)
      continue;
    int value = k;
    if (i >= 0)
      value = k - a[i];
    auto itr = lower_bound(b, b + m, value) - b;
    if (itr == m) {
      ans = max(ans, m + i + 1);
    } else if (b[itr] > value) {
      ans = max(ans, itr + i + 1);
    } else {
      ans = max(ans, itr + i + 2);
    }
  }
  cout << ans << endl;
  return 0;
}

//!

Error: 0

Fixed submission:

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int32_t main() {
  GO;
  int n, m, k;
  cin >> n >> m >> k;
  queue<int> a, b;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push(x);
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    b.push(x);
  }
  int sum = 0, count = 0;
  while (sum <= k) {
    if (a.empty() && b.empty())
      break;
    if ((a.empty() && !b.empty()) || a.front() > b.front()) {
      sum += b.front();
      b.pop();
      count++;
    } else if ((b.empty() && !a.empty()) || a.front() <= b.front()) {
      sum += a.front();
      a.pop();
      count++;
    }
  }
  if (sum <= k)
    cout << count << endl;
  else
    cout << count - 1 << endl;
  return 0;
}

//!
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e9)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
int sieve[10000001];
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> k;
  ll arr[n], brr[m];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  for (j = 0; j < m; j++)
    cin >> brr[j];
  for (i = 1; i < n; i++)
    arr[i] += arr[i - 1];
  for (j = 1; j < m; j++)
    brr[j] += brr[j - 1];
  z = 0;
  for (i = 0; i < n; i++) {
    if (arr[i] > k)
      break;
    x = arr[i];
    ll l, r, mid;
    l = 0;
    r = m - 1;
    y = -1;
    while (l <= r) {
      mid = (l + r) / 2;
      if (brr[mid] + x <= k) {
        y = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (y == -1) {
      z = max(z, i + 1);
      // break ;
    }
    z = max(z, i + 1 + y + 1);
  }
  for (i = 0; i < m; i++) {
    if (brr[i] > k)
      break;
    x = brr[i];
    ll l, r, mid;
    l = 0;
    r = n - 1;
    y = -1;
    while (l <= r) {
      mid = (l + r) / 2;
      if (arr[mid] + x <= k) {
        y = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (y == -1) {
      z = max(z, i + 1);
    }
    //   break ; } }
    z = max(z, i + 1 + y + 1);
  }
  cout << z;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
int arr[200001];
int brr[200001];
double PI = 3.14159265357;
int32_t main() {
  ll n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> k;
  // ll arr[n],brr[m] ;
  for (i = 0; i < n; i++)
    cin >> arr[i];
  for (i = 0; i < m; i++)
    cin >> brr[i];
  arr[n] = inf;
  brr[m] = inf;
  cnt = 0;
  i = 0;
  j = 0;
  x = k;
  while (i < n || j < m) {
    if (arr[i] < brr[j]) {
      if (arr[i] > x)
        break;
      cnt++;
      x = x - arr[i];
      i++;
    } else {

      if (brr[j] > x)
        break;
      cnt++;
      x = x - brr[j];
      j++;
    }
  }
  cout << cnt;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

ll a[200005], b[200005];

int main() {
  ios::sync_with_stdio(false);
  int n, m, q, ans = 0;
  ll w, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> w;
    a[i] = a[i - 1] + w;
  }
  for (int i = 1; i <= m; i++) {
    cin >> w;
    b[i] = b[i - 1] + w;
  }
  for (int i = 0; i <= n; i++) {
    w = k - a[i];
    if (w < 0)
      break;
    q = upper_bound(b + 1, b + 1 + m, w) - b - 1;
    ans = max(ans, i + q);
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

ll a[200005], b[200005];

int main() {
  ios::sync_with_stdio(false);
  ll n, m, w, k, q, p;
  cin >> n >> m >> k;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  for (ll i = 1; i <= m; i++)
    cin >> b[i];
  int x, y;
  x = y = 1, w = q = 0;
  while (x <= n || y <= m) {
    if (a[x] >= b[y] || x > n) {
      p = b[y];
      y++;
    } else {
      p = a[x];
      x++;
    }
    if (w + p > k)
      break;
    w += p;
    q++;
  }
  cout << q;
  return 0;
}