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

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO                                                                 \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define maxn 1000000

using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
signed main() {
  // FILEIO;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int n, m, k;
  cin >> n >> m >> k;
  int a[n];
  int b[m];
  int pref1[n + 1];
  int pref2[m + 1];
  pref1[0] = 0;
  pref2[0] = 0;
  for (int i = 0; i < n; ++i) {
    /* code */
    cin >> a[i];
    pref1[i + 1] = pref1[i] + a[i];
  }
  for (int i = 0; i < m; ++i) {
    /* code */
    cin >> b[i];
    pref2[i + 1] = pref2[i] + b[i];
  }
  int ans = -1;
  for (int i = 0; i <= n; i++) {
    int temp = pref1[i];
    int remain = k - temp;
    if (remain < 0)
      break;
    int start = 0;
    int end = m;
    while (start <= end) {
      int mid = (start + end) / 2;
      if (pref2[mid] > remain) {
        end = mid - 1;
      } else {
        start = mid + 1;
      }
    }
    ans = max(ans, i + end);
  }
  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO                                                                 \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define maxn 1000000

using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
int a[maxn];
int b[maxn];
signed main() {
  // FILEIO;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int n, m, k;
  cin >> n >> m >> k;
  int pref1[n + 1];
  int pref2[n + 1];
  pref1[0] = 0;
  pref2[0] = 0;
  for (int i = 0; i < n; ++i) {
    /* code */
    cin >> a[i];
    pref1[i + 1] = pref1[i] + a[i];
  }
  for (int i = 0; i < m; ++i) {
    /* code */
    cin >> b[i];
    pref2[i + 1] = pref2[i] + b[i];
  }
  int ans = -1;
  for (int i = 0; i <= n; i++) {
    int temp = pref1[i];
    int remain = k - temp;
    if (remain < 0)
      break;
    int start = 0;
    int end = m;
    while (start <= end) {
      int mid = (start + end) / 2;
      if (pref2[mid] > remain) {
        end = mid - 1;
      } else {
        start = mid + 1;
      }
    }
    ans = max(ans, i + end);
  }
  cout << ans;

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

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

int main() {
  long long int N, M, K;
  cin >> N >> M >> K;
  long long int A[N + 1], B[M + 1], sa[N + 1], sb[M + 1];
  sa[0] = 0;
  sb[0] = 0;
  long long int b_max = M, a_max = N, max = 0;
  for (long long int i = 1; i <= N; i++) {
    cin >> A[i];
    sa[i] = sa[i - 1] + A[i];
  }
  for (long long int i = 1; i <= M; i++) {
    cin >> B[i];
    sb[i] = sb[i - 1] + B[i];
  }
  for (long long int i = 0; i <= N; i++) {
    if (sa[i] < K) {
      long long int j = b_max;
      for (; (K < (sb[j] + sa[i])) && (j > 0); j--) {
        continue;
      }
      b_max = j;
      if (max < b_max + i)
        max = b_max + i;
      else
        continue;
    } else
      break;
  }
  for (long long int i = 0; i <= M; i++) {
    if (sb[i] < K) {
      long long int j = a_max;
      for (; (K < (sa[j] + sb[i])) && (j > 0); j--) {
        continue;
      }
      a_max = j;
      if (max < a_max + i)
        max = a_max + i;
      else
        continue;
    } else
      break;
  }
  cout << max;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long long int N, M, K;
  cin >> N >> M >> K;
  long long int A[N], B[M], a[N + 1], b[M + 1];
  a[0] = 0;
  b[0] = 0;
  int b_best = M, max = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    a[i + 1] = a[i] + A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    b[i + 1] = b[i] + B[i];
  }
  for (int i = 0; i < N + 1; i++) {
    for (int j = b_best; b[j] > (K - a[i]); j--) {
      b_best = j - 1;
    }
    if (max < b_best + i)
      max = b_best + i;
    else
      continue;
  }
  cout << max;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

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

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

  ll ans;
  if (k >= prefb[m])
    ans = m;
  else if (k < b[1])
    ans = 0;
  else
    ans = upper_bound(prefb.begin(), prefb.end(), k) - prefb.begin() - 1;
  for (int i = 1; i <= n; i++) {
    if (k - prefa[i] < 0)
      continue;
    if (k - prefa[i] >= prefb[m]) {
      ans = max(ans, i + m);
      continue;
    }
    if (k - prefa[i] < b[1]) {
      ans = max(ans, (ll)i);
      continue;
    }
    ans = max(ans, upper_bound(prefb.begin(), prefb.end(), k - prefa[i]) -
                       prefb.begin() - 1 + (ll)i);
  }

  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

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

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

  ll ans;
  if (k >= prefb[m])
    ans = m;
  else if (k < b[1])
    ans = 0;
  else
    ans = upper_bound(prefb.begin(), prefb.end(), k) - prefb.begin() - 1;
  for (int i = 1; i <= n; i++) {
    if (k - prefa[i] < 0)
      continue;
    if (k - prefa[i] >= prefb[m]) {
      ans = max(ans, i + m);
      continue;
    }
    if (k - prefa[i] < b[1]) {
      ans = max(ans, (ll)i);
      continue;
    }
    ans = max(ans, upper_bound(prefb.begin(), prefb.end(), k - prefa[i]) -
                       prefb.begin() - 1 + (ll)i);
  }

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

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

const double PI = acos(-1);
ll Asum[200005];
ll Bsum[200005];

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

  // Asum[0]=0の分だけ配列が1大きい
  rep(ii, N) {
    int i = ii + 1;
    cin >> Asum[i];
    Asum[i] += Asum[ii];
  }

  rep(ii, M) {
    int i = ii + 1;
    cin >> Bsum[i];
    Bsum[i] += Bsum[ii];
  }

  int ans = 0, j = M;
  rep(i, N + 1) {
    if (Asum[i] > K)
      break;
    // output for debug
    // cout << "Asum:" << Asum[i] << ",Bsum:" << Bsum[j] << "\\n";
    while (Bsum[j] > K - Asum[i]) {
      // output for debug
      // cout << "A:" << Asum[i] << ",B:" << Bsum[j] << "\\n";
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << "\\n";
  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>;
using Graph = vector<vector<int>>;

const double PI = acos(-1);
ll A[200005];
ll B[200005];

int main() {
  int N, M, K, sum = 0, res = 0;
  cin >> N >> M >> K;
  rep(i, N) { cin >> A[i]; }
  rep(i, M) { cin >> B[i]; }
  int k;
  for (k = 0; sum <= K; ++k) {
    sum += A[k];
  }
  int i, j, cmp;
  cmp = res = k;
  for (i = 0, j = 0; i <= k;) {
    if (sum + B[j] <= K) {
      sum += B[j];
      j++;
      res = max(res, ++cmp);
    } else {
      sum -= A[k - i];
      i++;
      cmp--;
      if (k - 1 < 0)
        break;
    }
  }
  cout << res << "\\n";
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repo(i, n) for (int i = 1; i <= n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x)                                                            \\
  for (auto elementPrintVec : x) {                                             \\
    cout << elementPrintVec << " ";                                            \\
  }                                                                            \\
  cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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]; }
  int anum = 0, bnum = 0;
  ll sum = 0;
  while (bnum < m && sum + b[bnum] <= k) {
    sum += b[bnum];
    bnum++;
  }
  while (anum < n && sum + a[anum] <= k) {
    sum += a[anum];
    anum++;
  }
  int ans = anum + bnum;
  for (int i = anum; i < n; i++) {
    sum += a[i];
    while (sum > k) {
      if (bnum <= 0) {
        break;
      }
      bnum--;
      sum -= b[bnum];
    }
    if (sum <= k) {
      ans = max(ans, i + 1 + bnum);
    }
  }

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repo(i, n) for (int i = 1; i <= n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x)                                                            \\
  for (auto elementPrintVec : x) {                                             \\
    cout << elementPrintVec << " ";                                            \\
  }                                                                            \\
  cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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]; }
  int anum = 0, bnum = 0;
  ll sum = 0;
  while (bnum < m && sum + b[bnum] <= k) {
    sum += b[bnum];
    bnum++;
  }
  while (anum < n && sum + a[anum] <= k) {
    sum += a[anum];
    anum++;
  }
  int ans = anum + bnum;
  for (int i = anum; i < n || bnum >= 0; i++) {
    sum += a[i];
    while (sum > k) {
      if (bnum < 0) {
        break;
      }
      sum -= b[bnum];
      bnum--;
    }
    ans = max(ans, i + 1 + bnum);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  long long int k;
  cin >> n >> m >> k;
  int a[n];
  int b[m];
  long long int c[n];
  long long int d[m];
  int i, j;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (j = 0; j < m; j++)
    cin >> b[j];
  c[0] = a[0];
  d[0] = b[0];
  for (i = 1; i < n; i++)
    c[i] = c[i - 1] + a[i];
  for (i = 1; i < m; i++)
    d[i] = d[i - 1] + b[i];
  int ans = 0;
  int t = -1;
  int l, r;
  int mi;
  l = 0;
  r = m - 1;
  while (l <= r) {
    mi = l + (r - l) / 2;
    if (d[mi] <= k) {
      t = mi;
      l = mi + 1;
    } else
      r = mi - 1;
  }
  if (t != -1)
    ans = max(ans, t + 1);
  for (i = 0; i < n && c[i] <= k; i++) {
    int l, r;
    l = 0;
    r = m - 1;
    int t = -1;
    while (l <= r) {
      int mi = l + (r - l) / 2;
      if (d[mi] + c[i] <= k) {
        t = mi;
        l = mi + 1;
      } else
        r = mi - 1;
    }
    if (t != -1)
      ans = max(ans, i + t + 2);
    else
      ans = max(ans, i + 1);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int a[200001];
long long int b[200001];
int n, m;
long long int f(int i, int j, int k) {
  if (i == n && j == m)
    return 0;
  if (i == n) {
    if (k < b[j])
      return 0;
    return 1 + f(i, j + 1, k - b[j]);
  }
  if (j == m) {
    if (k < a[i])
      return 0;
    return 1 + f(i + 1, j, k - a[i]);
  }
  if (k < a[i] && k < b[j])
    return 0;
  if (k >= a[i] && k >= b[j])
    return 1 + max(f(i + 1, j, k - a[i]), f(i, j + 1, k - b[j]));
  if (k >= a[i])
    return 1 + f(i + 1, j, k - a[i]);
  else
    return 1 + f(i, j + 1, k - b[j]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int k;
  cin >> n >> m >> k;
  int i;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < m; i++)
    cin >> b[i];
  cout << f(0, 0, k) << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

void Main() {
  int N, M, K;
  cin >> N >> M >> K;

  vector<long long> A(N + 1), B(M + 1);
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i <= N; i++) {
    int a;
    cin >> a;
    A[i] = A[i - 1] + a;
  }
  for (int i = 1; i <= M; i++) {
    int b;
    cin >> b;
    B[i] = B[i - 1] + b;
  }

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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: 0

Fixed submission:

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

void Main() {
  int N, M, K;
  cin >> N >> M >> K;

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

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

  int j = M;
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    while (K - a[i] < b[j])
      j--;
    ans = max(ans, (long long)i + j);
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool pred(ll cond, ll target) { return cond <= target; }

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

  for (int i = 0; i < m; ++i) {
    cin >> newB[i + 1];
    newB[i + 1] += newB[i];
  }

  int maxi = 0;
  for (int i = 0; i <= n; ++i) {
    if (newA[i] > k)
      continue;
    int lo = 0, hi = m, j;
    ll target = k - newA[i];
    if (!pred(newB[lo], target))
      j = lo;

    else if (pred(newB[hi], target))
      j = hi;
    else {
      while (hi - lo > 1) {
        int mi = lo + (hi - lo) / 2;
        if (pred(newB[mi], target))
          lo = mi;
        else
          hi = mi;
      }
      j = lo;
    }

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

  cout << maxi;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

  for (int i = 0; i < m; ++i)
    cin >> B[i];

  int maxi = 0;
  for (int i = 0; i <= n; ++i) {
    if (newA[i] > k)
      continue;
    ll suma = newA[i];
    int j = 0;
    while (j < (int)B.size() && (ll)B[j] + suma <= k) {
      suma += (ll)B[j];
      ++j;
    }

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

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

#include <bits/stdc++.h>
#include <string.h>
#define pb push_back
#define all(v) v.begin(), v.end()
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
using namespace std;

int main() {
  //    ios::sync_with_stdio(false);
  //    cin.tie(NULL),cout.tie(NULL);

  ll n, m, k, i, j, ans = 0;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  vector<ll>::iterator it;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  for (i = 0; i <= n; i++) {
    ll x = k - a[i];
    if (x < 0) {
      continue;
    }
    it = upper_bound(all(b), x);
    it--;
    x = it - b.begin();
    ans = max(ans, i + x);
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <string.h>
#define pb push_back
#define all(v) v.begin(), v.end()
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);

  ll n, m, k, i, j, ans = 0;
  cin >> n >> m >> k;
  queue<ll> a, b;
  for (i = 0; i < n; i++) {
    cin >> j;
    a.push(j);
  }
  for (i = 0; i < m; i++) {
    cin >> j;
    b.push(j);
  }
  ll x = 0, y = 0;
  while (ans < (n + m)) {
    if (!a.empty())
      x = a.front();
    if (!b.empty())
      y = b.front();
    if (x < y) {
      k -= x;
      if (k < 0)
        break;
      a.pop();
    } else {
      k -= y;
      if (k < 0)
        break;
      b.pop();
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main() {
  unsigned long n, m, k;
  std::cin >> n >> m >> k;

  std::vector<unsigned long long> ai, bi;
  ai.resize(n + 1);
  bi.resize(m + 1);
  ai[0] = 0;
  bi[0] = 0;
  for (auto i = 0; i < n; i++) {
    std::cin >> ai[i + 1];
    ai[i + 1] += ai[i]; // 累積和の計算
  }
  for (auto i = 0; i < m; i++) {
    std::cin >> bi[i + 1];
    bi[i + 1] += bi[i];
  }
  bi.push_back(10 ^ 9);

  unsigned int count = 0;
  for (unsigned int i = 0; i < ai.size(); ++i) {
    if (ai[i] <= k) {
      unsigned int idx_large = m + 1;
      unsigned int idx_small = 0;
      unsigned int step = (m + 1) >> 1;
      unsigned int j = step;
      while ((idx_large - idx_small) > 1) {
        step >>= 1;
        step = (step < 1) ? 1 : step;
        if (k >= (ai[i] + bi[j])) {
          idx_small = j;
          j += step;
        } else {
          idx_large = j;
          j -= step;
        }
      }
      count = std::max(count, i + idx_small);
    } else {
      break;
    }
  }

  std::cout << count << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main() {
  unsigned long n, m, k;
  std::cin >> n >> m >> k;

  std::vector<unsigned long long> ai, bi;
  ai.resize(n + 1);
  bi.resize(m + 1);
  ai[0] = 0;
  bi[0] = 0;
  for (auto i = 0; i < n; i++) {
    std::cin >> ai[i + 1];
    ai[i + 1] += ai[i]; // 累積和の計算
  }
  for (auto i = 0; i < m; i++) {
    std::cin >> bi[i + 1];
    bi[i + 1] += bi[i];
  }

  unsigned int count = 0;
  for (unsigned int i = 0; i < ai.size(); ++i) {
    if (ai[i] <= k) {
      unsigned int j = m;
      while (bi[j] + ai[i] > k) {
        --j;
      }
      count = std::max(count, i + j);
    }
  }

  std::cout << count << std::endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, n) for (ll i = 0; i < n; i++)
#define fb(i, n) for (ll i = n - 1; i >= 0; i--)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef pair<int, int> pii;
int main() {
  IOS;
  // int t; cin>>t;
  // ll M=pow(10,9)+7;
  int t = 1;
  while (t) {
    int n, m;
    cin >> n >> m;
    ll k;
    cin >> k;
    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 A[n + 1], B[m + 1];
    A[0] = 0;
    B[0] = 0;
    for (int i = 1; i <= n; i++)
      A[i] = A[i - 1] + a[i - 1];
    for (int i = 1; i <= m; i++)
      B[i] = B[i - 1] + b[i - 1];
    int i = 0, j = m;
    vector<int> v;
    int count = 0;
    while (1) {
      if (A[i] + B[j] > k && j >= 0 && i <= n) {
        j--;
      } else {
        if (j == 0) {
          if (A[i] <= k) {
            v.push_back(i);
            i++;
          } else {
            count = -1;
          }
        }
        if (i <= n && j >= 0 && A[i] + B[j] <= k) {
          v.push_back(i + j);
          // cout<<(i+j)<<" ";
          i++;
        }
      }
      if (j == -1) {
        break;
      }
      if (count == -1)
        break;
      if (i == n + 1)
        break;
    }
    sort(v.begin(), v.end());
    if (v.size() != 0)
      cout << v[v.size() - 1];
    else
      cout << "0\\n";
    t--;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, n) for (ll i = 0; i < n; i++)
#define fb(i, n) for (ll i = n - 1; i >= 0; i--)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef pair<int, int> pii;
int main() {
  IOS;
  // int t; cin>>t;
  // ll M=pow(10,9)+7;
  int t = 1;
  while (t) {
    int n, m;
    cin >> n >> m;
    ll k;
    cin >> k;
    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 A[n + 1], B[m + 1];
    A[0] = 0;
    B[0] = 0;
    for (int i = 1; i <= n; i++)
      A[i] = A[i - 1] + a[i - 1];
    for (int i = 1; i <= m; i++)
      B[i] = B[i - 1] + b[i - 1];
    int i = 0, j = m;
    vector<int> v;
    while (1) {
      if (A[i] + B[j] > k && j >= 0 && i <= n) {
        j--;
      } else {
        v.push_back(i + j);
        i++;
      }
      if (i == n + 1 && j == -1) {
        break;
      }
    }
    sort(v.begin(), v.end());
    cout << v[v.size() - 1] << "\\n";
    t--;
  }
  return 0;
}