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

#include <bits/stdc++.h>

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

  int64_t A, B;
  int64_t sum_A[N + 1] = {0};
  int64_t sum_B[M + 1] = {0};
  for (int i = 0; i < N; ++i) {
    std::cin >> A;
    sum_A[i + 1] = sum_A[i] + A;
  }

  for (int i = 0; i < M; ++i) {
    std::cin >> B;
    sum_B[i + 1] = sum_B[i] + B;
  }

  int ans = 0;
  int cur = 0;
  for (int i = N; i >= 0; --i) {
    if (sum_A[i] > K) {
      continue;
    }

    for (int j = cur; j <= M; ++j) {
      if ((sum_A[i] + sum_B[j]) > K) {
        break;
      }

      ans = std::max(i + j, ans);
      cur = j;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

  int64_t A[N];
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }

  int64_t B[N];
  for (int i = 0; i < M; ++i) {
    std::cin >> B[i];
  }

  int64_t cur = 0;
  int pos_a = 0, pos_b = 0;
  while (cur <= K) {
    if (pos_a == N && pos_b == M) {
      break;
    } else if (pos_a == N) {
      if (cur + B[pos_b] <= K) {
        cur += B[pos_b];
        ++pos_b;
      } else {
        break;
      }
    } else if (pos_b == M) {
      if ((cur + A[pos_a]) <= K) {
        cur += A[pos_a];
        ++pos_a;
      } else {
        break;
      }
    } else {
      if (A[pos_a] <= B[pos_b] && (cur + A[pos_a]) <= K) {
        cur += A[pos_a];
        ++pos_a;
      } else if (cur + B[pos_b] <= K) {
        cur += B[pos_b];
        ++pos_b;
      } else {
        break;
      }
    }
  }

  std::cout << pos_a + pos_b << std::endl;

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

#include <iostream>

typedef long long ll;

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

  int A[N + 1], B[M + 1];
  ll sa[N + 1], sb[M + 1];
  sa[0] = 0;
  sb[0] = 0;
  for (int i = 1; i <= N; ++i) {
    std::cin >> A[i];
    sa[i] = sa[i - 1] + A[i];
  }
  for (int i = 1; i <= M; ++i) {
    std::cin >> B[i];
    sb[i] = sb[i - 1] + B[i];
  }

  if (sa[N] + sb[M] <= K) {
    std::cout << N + M << std::endl;
    return 0;
  }

  int ans = 0;
  int bi = M;
  for (int i = 0; i <= N; ++i) {
    for (int j = bi; j >= 0; --j) {
      if (sa[i] + sb[j] <= K) {
        ans = std::max(ans, i + j);
        break;
      } else {
        bi = j;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

typedef long long ll;

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

  int A[N + 1], B[M + 1];
  ll sa[N + 1], sb[M + 1];
  sa[0] = 0;
  sb[0] = 0;
  for (int i = 1; i <= N; ++i) {
    std::cin >> A[i];
    sa[i] = sa[i - 1] + A[i];
  }
  for (int i = 1; i <= M; ++i) {
    std::cin >> B[i];
    sb[i] = sb[i - 1] + B[i];
  }

  if (sa[N] + sb[M] <= K) {
    std::cout << N + M << std::endl;
    return 0;
  }

  int ans = 0;
  int bi = M;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= bi; ++j) {
      if (sa[i] + sb[j] <= K) {
        ans = std::max(ans, i + j);
      } else {
        bi = j;
        break;
      }
    }
  }

  std::cout << ans << std::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<ll> A(N + 1, 0);
  vector<ll> B(M + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
    A.at(i) += A.at(i - 1);
  }
  for (int i = 1; i <= M; i++) {
    cin >> B.at(i);
    B.at(i) += B.at(i - 1);
  }

  int j = M;
  int ans = 0;
  rep(i, N + 1) {
    if (A.at(i) > K)
      break;
    while (A.at(i) + B.at(j) > K && j > 0)
      j--;
    ans = max(ans, i + j);
  }
  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;
  vector<int> A(N);
  vector<int> B(M);
  rep(i, N) cin >> A.at(i);
  rep(i, M) cin >> B.at(i);

  int ans = 0;
  int time = 0;
  int j = 0;
  rep(i, N) {
    while (A.at(i) > B.at(j)) {
      if (time + B.at(j) <= K) {
        time += B.at(j);
        j++;
        ans++;
      }
    }
    if (time + A.at(i) <= K) {
      time += A.at(i);
      ans++;
    } else {
      break;
    }
  }
  while (j < M) {
    if (time + B.at(j) <= K) {
      time += B.at(j);
      j++;
      ans++;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n, m, x;
  cin >> n >> m >> x;
  long long a[n], b[m];
  for (long long i = 0; i < n; i++)
    cin >> a[i];
  for (long long i = 0; i < m; i++)
    cin >> b[i];

  long long ans = 0, sum = 0, i = 0, j = 0;
  while (i < n && sum + a[i] <= x) {
    sum += a[i];
    i++;
  }
  ans = i;

  while (j < m && i >= 0) {
    sum += b[j];
    j++;
    while (sum > x && i > 0) {
      i--;
      sum -= a[i];
    }
    if (sum <= x && i + j > ans)
      ans = i + j;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

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

  long long i = 0, j = 0;
  long long track = 0;
  long long ans = 0;
  while (true) {
    long long nextAdd = 0;
    if (i < n && j < m) {
      if (a[i] < b[j]) {
        nextAdd = a[i];
        i++;
      } else if (b[j] < a[i]) {
        nextAdd = b[j];
        j++;
      } else if (a[i] == b[j]) {
        long long sumA = 0;
        long long sumB = 0;
        for (long long m = i; m < n; m++) {
          sumA += a[m];
        }
        for (long long l = j; l < m; l++) {
          sumB += a[l];
        }
        if (sumA >= sumB) {
          nextAdd = b[j];
          j++;
        } else {
          nextAdd = a[i];
          i++;
        }
      }
    } else if (j < m) {
      nextAdd = b[j];
      j++;
    } else if (i < n) {
      nextAdd = a[i];
      j++;
    }

    // cout << nextAdd << endl;
    if (track + nextAdd > k) {
      // cout << "track + nextAdd = " << track + nextAdd << endl;
      break;
    }
    track += nextAdd;
    ans++;

    if (i >= n && j >= m)
      break;
  }

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int m, n;
ll k;

vector<ll> a, b;

int main() {
  int bkmax = 0;
  int amax, bmax;
  int i, j;

  cin >> n >> m >> k;
  a.resize(n + 1);
  b.resize(m + 1);

  a[0] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
    // printf("a[%d] = %lld\\n", i, a[i]);
    if (a[i - 1] <= k && a[i] > k)
      amax = i - 1;
  }
  if (a[n] <= k)
    amax = n;
  // printf("amax = %d\\n", amax);
  b[0] = 0;
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
    // printf("b[%d] = %lld\\n", i, b[i]);
    if (b[i - 1] <= k && b[i] > k)
      bmax = i - 1;
  }
  if (b[m] <= k)
    bmax = m;
  // printf("bmax = %d\\n", bmax);

  i = amax;
  for (j = 0; j <= bmax; j++) {
    if (a[i] + b[j] > k) {
      break;
    }
  }
  j--;
  bkmax = max(bkmax, i + j);
  // printf("bkmax = %d, a[%d]+b[%d] = %lld\\n", bkmax, i, j, a[i]+b[j]);
  for (i--; i >= 0 && j <= m; i--) {
    while (a[i] + b[j] <= k && j <= m) {
      bkmax = max(bkmax, i + j);
      // printf("bkmax = %d, a[%d]+b[%d] = %lld\\n", bkmax, i, j, a[i]+b[j]);
      j++;
    }
  }

  cout << bkmax << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int m, n;
ll k;

vector<ll> a, b;

int main() {
  int bkmax = 0;
  int amax, bmax;
  int i, j;

  cin >> n >> m >> k;
  a.resize(n + 1);
  b.resize(m + 1);

  a[0] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
    // printf("a[%d] = %lld\\n", i, a[i]);
    if (a[i - 1] <= k && a[i] > k)
      amax = i - 1;
  }
  if (a[n] <= k)
    amax = n;
  // printf("amax = %d\\n", amax);
  b[0] = 0;
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
    // printf("b[%d] = %lld\\n", i, b[i]);
    if (b[i - 1] <= k && b[i] > k)
      bmax = i - 1;
  }
  if (b[m] <= k)
    bmax = m;
  // printf("bmax = %d\\n", bmax);

  i = amax;
  for (j = 0; j <= bmax; j++) {
    if (a[i] + b[j] > k) {
      break;
    }
  }
  j--;
  bkmax = max(bkmax, i + j);
  // printf("bkmax = %d, a[%d]+b[%d] = %lld\\n", bkmax, i, j, a[i]+b[j]);
  for (i--; i >= 0; i--) {
    while (a[i] + b[j] <= k) {
      bkmax = max(bkmax, i + j);
      // printf("bkmax = %d, a[%d]+b[%d] = %lld\\n", bkmax, i, j, a[i]+b[j]);
      j++;
    }
  }

  cout << bkmax << endl;

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

#include <bits/stdc++.h>

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  IOS;
  int n, m, k, i;
  cin >> n >> m >> k;
  vi a(n + 1), b(m + 1);
  vi suma(n + 1), sumb(m + 1);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    suma[i] = suma[i - 1] + a[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    sumb[i] = sumb[i - 1] + b[i];
  }
  int ans = 0;
  for (i = 0; i <= n; i++) {
    if (suma[i] > k)
      break;
    else {
      int x = k - suma[i];
      auto it = upper_bound(sumb.begin(), sumb.end(), x);
      int pos = it - sumb.begin() - 1;
      if (pos < 0)
        pos = 0;
      ans = max(ans, i + pos);
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  IOS;
  int n, m, k, i;
  cin >> n >> m >> k;
  vi a(n + 1), b(n + 1);
  vi suma(n + 1), sumb(m + 1);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    suma[i] = suma[i - 1] + a[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    sumb[i] = sumb[i - 1] + b[i];
  }
  int ans = 0;
  for (i = 0; i <= n; i++) {
    if (suma[i] > k)
      break;
    else {
      int x = k - suma[i];
      auto it = upper_bound(sumb.begin(), sumb.end(), x);
      int pos = it - sumb.begin() - 1;
      if (pos < 0)
        pos = 0;
      ans = max(ans, i + pos);
    }
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; (ll)(b) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  REP(i, n) {
    ll x;
    cin >> x;
    a[i + 1] = a[i] + x;
  }
  REP(i, m) {
    ll x;
    cin >> x;
    b[i + 1] = b[i] + x;
  }
  ll ac = upper_bound(ALL(a), k) - a.begin();
  ll res = 0;
  REP(i, ac) {
    ll times = a[i];
    ll bc = upper_bound(ALL(b), k - times) - b.begin();
    if (0 < bc)
      res = max(res, i + bc - 1);
  }
  cout << res << endl;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; (ll)(b) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n, 0), b(m + 1, 0);
  REP(i, n) {
    ll x;
    cin >> x;
    a[i + 1] = a[i] + x;
  }
  REP(i, m) {
    ll x;
    cin >> x;
    b[i + 1] = b[i] + x;
  }

  ll res = 0;
  REP(i, n + 1) {
    ll times = a[i];
    ll bc = upper_bound(ALL(b), k - times) - b.begin();
    if (0 < bc)
      res = max(res, i + bc - 1);
  }
  cout << res << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[200001], b[200001], A, ans, L;
vector<ll> v, u;
int main(void) {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  v.push_back(0);
  u.push_back(0);
  for (int i = 0; i < n; i++) {
    v.push_back(v[i] + a[i]);
  }
  for (int i = 0; i < m; i++) {
    u.push_back(u[i] + b[i]);
  }
  for (ll i = 0LL; i <= n; i++) {
    A = k - v[i];
    // cout<<A<<endl;
    if (A < 0)
      continue;
    L = upper_bound(u.begin(), u.end(), A) - u.begin();
    // cout<<i<<" "<<L<<endl;
    ans = max(ans, i + L - 1);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[200001], b[200001], A, ans, L;
vector<ll> v, u;
int main(void) {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  v.push_back(0);
  u.push_back(0);
  for (int i = 0; i < n; i++) {
    v.push_back(v[i] + a[i]);
  }
  for (int i = 0; i < m; i++) {
    u.push_back(v[i] + b[i]);
  }
  for (ll i = 0LL; i <= n; i++) {
    A = k - v[i];
    // cout<<A<<endl;
    if (A < 0)
      continue;
    L = upper_bound(u.begin(), u.end(), A) - u.begin();
    // cout<<i<<" "<<L<<endl;
    ans = max(ans, i + L - 1);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[m];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<long long> sa(n + 1);
  sa[0] = 0;
  for (int i = 1; i <= n; i++) {
    sa[i] = sa[i - 1] + a[i - 1];
  }
  vector<long long> sb(m + 1);
  sb[0] = 0;
  for (int i = 1; i <= m; i++) {
    sb[i] = sb[i - 1] + b[i - 1];
  }
  int o = 0;
  for (int i = 0; i <= n; i++) {
    if (k - sa[i] >= 0)
      o = max((long)o, i + (upper_bound(sb.begin(), sb.end(), k - sa[i]) -
                            sb.begin() - 1));
  }
  cout << o << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[m];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<long long> sa(n + 1);
  sa[0] = 0;
  for (int i = 1; i <= n; i++) {
    sa[i] = sa[i - 1] + a[i - 1];
  }
  vector<long long> sb(n + 1);
  sb[0] = 0;
  for (int i = 1; i <= m; i++) {
    sb[i] = sb[i - 1] + b[i - 1];
  }
  int o = 0;
  for (int i = 0; i <= n; i++) {
    if (k - sa[i] > 0)
      o = max((long)o, i + (upper_bound(sb.begin(), sb.end(), k - sa[i]) -
                            sb.begin() - (k - sa[i] > sb[m - 1] ? 0 : 1)));
  }
  cout << o << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<long long int> asum;
  vector<long long int> bsum;

  asum.push_back(0);
  bsum.push_back(0);

  rep(i, n) {
    int a;
    cin >> a;

    asum.push_back(asum[i] + a);
  }

  rep(i, m) {
    int a;
    cin >> a;

    bsum.push_back(bsum[i] + a);
  }

  int ans = 0;

  rep(i, n + 1) {
    int left = 0;
    int right = m;
    int p = (left + right) / 2;

    while (left + 1 != right) {
      if (asum[i] + bsum[p] <= k) {
        ans = max(ans, i + p);
        left = p;
      } else {
        right = p;
      }

      p = (left + right) / 2;
    }

    if (asum[i] + bsum[left] <= k)
      ans = max(ans, i + left);
    if (asum[i] + bsum[right] <= k)
      ans = max(ans, i + right);

    // cout << left << " " << p << " " << right << endl;
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<long long int> asum;
  vector<long long int> bsum;

  asum.push_back(0);
  bsum.push_back(0);

  rep(i, n) {
    int a;
    cin >> a;
    asum.push_back(asum[i] + a);
  }

  rep(i, m) {
    int a;
    cin >> a;
    bsum.push_back(bsum[i] + a);
  }

  int ans = 0;

  rep(i, n + 1) {
    rep(j, m + 1) {
      long long int sum = asum[i] + bsum[j];

      if (sum <= k && ans < i + j)
        ans = i + j;
    }
  }

  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
  int x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-')
      f = -1;
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
ll a[200005], b[200005], n, m, k, ans;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    a[i] = a[i - 1] + read();
  for (int i = 1; i <= m; i++)
    b[i] = b[i - 1] + read();
  ll now = 0;
  while (b[now] <= k && now <= m)
    now++;
  now--;
  ans = now;
  for (int i = 1; i <= n; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[now] > k)
      now--;
    ans = max(ans, i + now);
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
  int x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-')
      f = -1;
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
ll a[100005], b[100005], n, m, k, ans;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    a[i] = a[i - 1] + read();
  for (int i = 1; i <= m; i++)
    b[i] = b[i - 1] + read();
  ll now = 0;
  while (b[now] <= k && now <= m)
    now++;
  now--;
  ans = now;
  for (int i = 1; i <= n; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[now] > k)
      now--;
    ans = max(ans, i + now);
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define pf push_front
#define np next_permutation
#define pp prev_permutation
#define fill(x, y) memset((x), y, sizeof(x))
#define rep(x, y, z) for (int x = y; x < z; x++)
#define rep1(x, y, z) for (int x = y; x >= z; x--)
#define all(x) (x).begin(), (x).end()

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, x = 0, y = 0;
  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];
  long long c = 0, p = 0;
  while (1) {
    bool s = false;
    bool t = false;
    if (a[x] <= b[y] && (a[x] + c) <= k) {
      c += a[x];
      s = true;
      p++;
    } else if (b[y] < a[x] && (b[y] + c) <= k) {
      c += b[y];
      t = true;
      p++;
    } else
      break;
    if (s == true)
      x++;
    if (t == true)
      y++;
  }
  cout << p << endl;
}