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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  a.at(0) = 0;
  b.at(0) = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a.at(i);
    a.at(i) = a.at(i - 1) + a.at(i);
  }
  for (ll i = 1; i <= m; i++) {
    cin >> b.at(i);
    b.at(i) = b.at(i - 1) + b.at(i);
  }
  ll ans = 0;
  ll j = m;
  for (ll i = 0; i <= n; i++) {
    if (a.at(i) > k)
      break;
    while (b.at(j) > k - a.at(i))
      j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  queue<ll> qa;
  queue<ll> qb;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    qa.push(a.at(i));
  }
  for (ll i = 0; i < m; i++) {
    cin >> b.at(i);
    qb.push(b.at(i));
  }
  ll sum = 0;
  ll count = 0;
  for (ll i = 0; i < n + m; i++) {
    if (qa.front() > qb.front() || qa.empty()) {
      if (sum + qb.front() <= k) {
        sum = sum + qb.front();
        count++;
        qb.pop();
      } else {
        cout << count << endl;
        return 0;
      }
    } else {
      if (sum + qa.front() <= k || qb.empty()) {
        sum = sum + qa.front();
        count++;
        qa.pop();
      } else {
        cout << count << endl;
        return 0;
      }
    }
  }
  cout << count << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

long solve(long n, long m, long k, const std::vector<long> &minutes_a,
           const std::vector<long> &minutes_b) {
  long count_a = 0;
  long sum_a = 0;
  for (; count_a < n;) {
    const auto a = minutes_a.at(count_a);
    if (sum_a + a > k)
      break;
    sum_a += a;
    ++count_a;
  }

  long result = count_a;

  long count_b = 0;
  long sum_b = 0;
  for (; count_b < m;) {
    const auto b = minutes_b.at(count_b);

    while (sum_a > 0 && sum_a + sum_b + b > k) {
      --count_a;
      sum_a -= minutes_a.at(count_a);
    }

    if (sum_a + sum_b + b > k)
      break;
    sum_b += b;
    ++count_b;
    result = std::max(result, count_a + count_b);
  }

  return result;
}

int main() {
  long n, m, k;
  std::cin >> n >> m >> k;
  std::vector<long> minutes_a(n);
  std::vector<long> minutes_b(m);
  for (auto &a : minutes_a) {
    std::cin >> a;
  }
  for (auto &b : minutes_b) {
    std::cin >> b;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, m, k, minutes_a, minutes_b) << std::endl;
}


Error: 0

Fixed submission:

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

long solve(long n, long m, long k, const std::vector<long> &minutes_a,
           const std::vector<long> &minutes_b) {
  long count_a = 0;
  long sum_a = 0;
  for (; count_a < n;) {
    const auto a = minutes_a.at(count_a);
    if (sum_a + a > k)
      break;
    sum_a += a;
    ++count_a;
  }

  long result = count_a;

  long count_b = 0;
  long sum_b = 0;
  for (; count_b < m;) {
    const auto b = minutes_b.at(count_b);

    while (sum_a > 0 && sum_a + sum_b + b > k) {
      sum_a -= minutes_a.at(count_a);
      --count_a;
    }

    if (sum_a + sum_b + b > k)
      break;
    sum_b += b;
    ++count_b;
    result = std::max(result, count_a + count_b);
  }

  return result;
}

int main() {
  long n, m, k;
  std::cin >> n >> m >> k;
  std::vector<long> minutes_a(n);
  std::vector<long> minutes_b(m);
  for (auto &a : minutes_a) {
    std::cin >> a;
  }
  for (auto &b : minutes_b) {
    std::cin >> b;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, m, k, minutes_a, minutes_b) << std::endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
//////////////////////////////////

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

  vector<long long> aa;
  vector<long long> bb;
  long long tmp = 0;
  aa.push_back(0);
  for (int i = 0; i < n; i++) {
    tmp += a[i];
    aa.push_back(tmp);
  }
  tmp = 0;
  bb.push_back(0);
  for (int i = 0; i < m; i++) {
    tmp += b[i];
    bb.push_back(tmp);
  }

  long long ans = 0;
  tmp = m;
  for (long long i = 0; i <= n; i++) {
    if (aa[i] > k)
      break;
    for (long long j = tmp; j >= 0; j--) {
      if (bb[j] <= k - aa[i]) {
        tmp = j;
        ans = max(ans, i + j);
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

// EOF

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
//////////////////////////////////

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

  vector<long long> aa;
  vector<long long> bb;
  long long tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += a[i];
    aa.push_back(tmp);
  }
  tmp = 0;
  for (int i = 0; i < m; i++) {
    tmp += b[i];
    bb.push_back(tmp);
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long ai = i + 1;
    long long bi = upper_bound(all(bb), k - aa[i]) - bb.begin();
    if (aa[ai - 1] + bb[bi - 1] > k)
      continue;
    ans = max(ans, ai + bi);
  }
  for (int i = 0; i < m; i++) {
    long long bi = i + 1;
    long long ai = upper_bound(all(aa), k - bb[i]) - bb.begin();
    if (aa[ai - 1] + bb[bi - 1] > k)
      continue;
    ans = max(ans, ai + bi);
  }
  cout << ans << endl;

  return 0;
}

// EOF
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)

int main() {

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

  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (ll i = 0; i < M; i++) {
    cin >> B[i];
  }

  vector<ll> arui(N + 1);
  vector<ll> brui(M + 1);
  for (ll i = 0; i < N; i++) {
    arui[i + 1] = arui[i] + A[i];
  }

  for (ll i = 0; i < M; i++) {
    brui[i + 1] = brui[i] + B[i];
  }

  ll ans = 0;
  ll now = M;
  ll f = 1;
  for (ll i = 0; i <= N; i++) {
    for (ll j = now; j >= 0; j--) {
      if (K >= arui[i] + brui[j]) {
        now = j;
        ans = max(ans, i + j);
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)

int main() {

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

  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (ll i = 0; i < M; i++) {
    cin >> B[i];
  }

  vector<ll> arui(N + 1);
  vector<ll> brui(M + 1);

  for (ll i = 0; i < N; i++) {
    arui[i + 1] = arui[i] + A[i];
  }

  for (ll i = 0; i < M; i++) {
    brui[i + 1] = brui[i] + B[i];
  }

  ll ans = 0;
  ll am = 0;
  ll bm = 0;
  for (ll i = N; i >= 0; i--) {
    if (arui[i] <= K) {
      am = i;
      break;
    }
  }

  for (ll i = M; i >= 0; i--) {
    if (brui[i] <= K) {
      bm = i;
      break;
    }
  }

  ans = max(am, bm);
  ll now = 0;
  for (ll i = am; i >= 0; i--) {
    for (ll j = now; j <= bm; j++) {
      if (j + i > ans) {
        if (arui[i] + brui[j] <= K) {
          ans = j + i;
          now = j;
        } else {
          break;
        }
      }
    }
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
const int NMAX = 100005;
using namespace std;

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

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

  int j = m;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ll d = suma[i];
    if (d > k)
      break;
    for (j; j >= 0; j--) {
      if (d + sumb[j] <= k)
        break;
    }
    ans = max(ans, i + j);
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
const int NMAX = 100005;
using namespace std;

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

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

  int j = m;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ll d = suma[i];
    if (d > k)
      break;
    for (j = m; j >= 0; j--) {
      if (d + sumb[j] <= k)
        break;
    }
    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;
#define endl '\\n'
#define rep(i, n)                                                              \\
  ;                                                                            \\
  for (long long i = 0; i < (n); i++)
using ll = long long;
using P = pair<long long, long long>;
template <class T> using vec = vector<T>;
const ll inf = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vec<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vec<ll> sa(n + 1), sb(m + 1);
  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];
  ll res = 0;
  rep(i, n + 1) {
    ll t = k - sa[i];
    if (t < 0)
      break;
    res =
        max(res,
            i - 1 + distance(sb.begin(), upper_bound(sb.begin(), sb.end(), t)));
  }
  cout << res << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define rep(i, n)                                                              \\
  ;                                                                            \\
  for (long long i = 0; i < (n); i++)
using ll = long long;
using P = pair<long long, long long>;
template <class T> using vec = vector<T>;
const ll inf = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vec<ll> a(n + 1), b(m + 1);
  rep(i, n) cin >> a[i];
  a[n] = inf;
  rep(i, m) cin >> b[i];
  b[n] = inf;
  ll a_num = 0, b_num = 0, t = 0, res = 0;
  while (t <= k || a_num + b_num == n + m) {
    if (a[a_num] < b[b_num]) {
      res++;
      t += a[a_num];
      a_num++;
    } else if (a[a_num] > b[b_num]) {
      res++;
      t += b[b_num];
      b_num++;
    } else {
      bool r = false;
      for (ll i = 1; i < min(n - 1 - a_num, m - 1 - b_num); i++) {
        if (a[a_num + i] < b[b_num + i]) {
          res++;
          t += a[a_num];
          a_num++;
          r = true;
          break;
        } else if (a[a_num + i] > b[b_num + i]) {
          res++;
          t += b[b_num];
          b_num++;
          r = true;
          break;
        } else {
          if (a[a_num + i - 1] < a[a_num + i]) {
            if (n - a_num < m - b_num) {
              res++;
              t += b[b_num];
              b_num++;
              r = true;
              break;
            } else {
              res++;
              t += a[a_num];
              a_num++;
              r = true;
              break;
            }
          }
        }
      }
      if (!r) {
        if (n - a_num < m - b_num) {
          res++;
          t += b[b_num];
          b_num++;
          r = true;

        } else {
          res++;
          t += a[a_num];
          a_num++;
          r = true;
        }
      }
    }
  }
  if (t > k)
    res--;
  cout << res << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mxN = 2e5;
int n, m;
ll k, a[mxN + 1], b[mxN + 1];

void test_case() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i + 1];
    b[i + 1] += b[i];
  }
  int ans = 0;
  for (int i = 0, j = m; i <= n; ++i) {
    if (a[i] > k)
      break;
    while (a[i] + b[j] > k) {
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << "\\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  test_case();
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const long int mxN = 2e5;
long int a[mxN], b[mxN], n, m, k, x;

void test_case() {
  // int a[100], n;
  // cin >> n;
  // for(int i = 0; i < n; ++i) {
  // cin >> a[i];
  //}
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  if (a[0] > k) {
    cout << 0 << "\\n";
    return;
  }
  vector<long int> v;
  for (int i = 0; i < n + m; ++i) {
    if (i % 2 == 0) {
      v.push_back(a[i]);
    } else {
      v.push_back(b[i]);
    }
  }
  long int sum = 0, cnt = 0;
  for (int i = 0; i < n + m; ++i) {
    if (sum < k) {
      sum += v[i];
      cnt++;
    }
  }
  cout << cnt << "\\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // int T;
  // cin >> T;
  // while(T--) {
  // test_case();
  //}
  test_case();
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  long long int x;
  long long int a[n + 1], b[m + 1];
  a[0] = b[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[i] = a[i - 1] + x;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    b[i] = b[i - 1] + x;
  }
  long long int ans = 0;
  int j = m;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k) {
      break;
    }
    while (b[j] > k - a[i]) {
      j--;
    }
    ans = max(ans, (long long int)i + j);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
#define for_int(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep_int(i, a, b) for (int i = (a); i >= (b); --i)
#define for_ll(i, a, b) for (ll i = (a); i <= (b); ++i)
#define rep_ll(i, a, b) for (ll i = (a); i >= (b); --i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6 + 5
#define quick_pow_mod 1e9 + 7
#define PII pair<int, int>
using namespace std;

// 快读
ll read() {
  char c = getchar();
  ll x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - 48;
  return x * f;
}
const int N = 2e5 + 5;
ll a[N], b[N], sum[N];
ll k, n, m;
int ans;
int main() {
  n = read();
  m = read();
  k = read();
  for_ll(i, 1, n) a[i] = read() + a[i - 1];
  for_ll(i, 1, m) b[i] = read() + b[i - 1];
  int p = m;
  for_int(i, 0, n) {
    if (a[i] > k)
      break;
    for (int j = p; j >= 0; --j)
      if (b[j] <= k - a[i]) {
        ans = max(ans, i + j);
        p = j;
        break;
      }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define for_int(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep_int(i, a, b) for (int i = (a); i >= (b); --i)
#define for_ll(i, a, b) for (ll i = (a); i <= (b); ++i)
#define rep_ll(i, a, b) for (ll i = (a); i >= (b); --i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6 + 5
#define quick_pow_mod 1e9 + 7
#define PII pair<int, int>
using namespace std;
// 快读
ll read() {
  char c = getchar();
  ll x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - 48;
  return x * f;
}
const int N = 2e5 + 5;
ll a[N], b[N], sum[N];
ll ans, k, n, m;
int main() {
  n = read();
  m = read();
  k = read();
  for_ll(i, 1, n) a[i] = read() + a[i - 1];
  for_ll(i, 1, m) b[i] = read() + b[i - 1];
  ll j = m, p1 = n;
  while (a[p1] > k)
    p1--;
  while (b[j] > k)
    j--;
  for (; j >= 0; --j)
    for (int i = 0; i <= p1 && b[j] + a[i] <= k; ++i)
      ans = max(ans, i + j);
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#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() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 1);
  vector<ll> B(m + 1);
  vector<ll> sum_a(n + 1);
  vector<ll> sum_b(m + 1);

  ll now_data_num = n;

  sum_a.at(0) = 0;
  sum_b.at(0) = 0;

  ll max = 0;

  for (ll i = 1; i <= n; i++) {
    cin >> A.at(i);
    sum_a.at(i) = sum_a.at(i - 1) + A.at(i);
    if (sum_a.at(i) > k) {
      if (now_data_num == n) {
        now_data_num = i;
      }
    } else {
      max = i;
    }
  }

  for (ll i = 1; i <= m; i++) {
    cin >> B.at(i);
    sum_b.at(i) = sum_b.at(i - 1) + B.at(i);
    if (sum_b.at(i) > k) {
      continue;
    }
    while (1) {
      if (now_data_num < 0) {
        break;
      }
      if (sum_b.at(i) + sum_a.at(now_data_num) > k) {
        now_data_num--;
      } else {
        if (max < i + now_data_num) {
          max = i + now_data_num;
        }
        break;
      }
    }
  }

  cout << max << endl;
}

Error: TLE

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() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 1);
  vector<ll> B(m + 1);
  vector<ll> sum_a(n + 1);
  vector<ll> sum_b(m + 1);

  sum_a.at(0) = 0;
  sum_b.at(0) = 0;

  for (ll i = 1; i <= n; i++) {
    cin >> A.at(i);
    sum_a.at(i) = sum_a.at(i - 1) + A.at(i);
  }
  for (ll i = 1; i <= m; i++) {
    cin >> B.at(i);
    sum_b.at(i) = sum_b.at(i - 1) + B.at(i);
  }

  int max = 0;

  for (int i = 0; i <= n; i++) {
    if (k < sum_a.at(i)) {
      continue;
    }
    int temp_max = 0;
    for (int j = 0; j <= m; j++) {
      if (sum_a.at(i) + sum_b.at(j) <= k) {
        temp_max = i + j;
      } else {
        break;
      }
    }
    if (temp_max > max) {
      max = temp_max;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

using vi = vector<int>;

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

  int n, m, k;
  cin >> n >> m >> k;
  vi psa(n + 1), psb(m + 1);
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    psa.at(i) = min(k + 1, psa.at(i - 1) + a);
  }
  for (int i = 1; i <= m; i++) {
    int b;
    cin >> b;
    psb.at(i) = min(k + 1, psb.at(i - 1) + b);
  }

  int ans = 0;
  for (int i = upper_bound(psa.begin(), psa.end(), k) - psa.begin() - 1, j = 0;
       i >= 0; i--) {
    while (j <= m && psa.at(i) + psb.at(j) <= k) {
      j++;
    }
    ans = max(ans, i + j - 1);
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

using vi = vector<int>;

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

  int n, m, k;
  cin >> n >> m >> k;
  vi psa(n + 1), psb(m + 1);
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    psa.at(i) = min(k + 1, psa.at(i - 1) + a);
  }
  for (int i = 1; i <= m; i++) {
    int b;
    cin >> b;
    psb.at(i) = min(k + 1, psb.at(i - 1) + b);
  }

  int ans = 0;
  for (int i = upper_bound(psa.begin(), psa.end(), k) - psa.begin() - 1, j = 0;
       i >= 0; i--) {
    while (psa.at(i) + psb.at(j) <= k) {
      j++;
    }
    ans = max(ans, i + j - 1);
  }

  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++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
  LL N, M, K;
  cin >> N >> M >> K;
  vector<LL> A(N);
  vector<LL> B(M);
  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];

  vector<LL> Arui(N + 1);
  vector<LL> Brui(M + 1);
  Arui[0] = 0;
  Brui[0] = 0;

  rep(i, N) { Arui[i + 1] = Arui[i] + A[i]; }
  rep(i, M) { Brui[i + 1] = Brui[i] + B[i]; }

  LL ans = 0;

  rep(i, N + 1) {
    LL tmp = 0;
    LL lim = K - Arui[i];
    if (lim < 0)
      continue;
    tmp = i;
    LL lb = 0;
    LL ub = M + 1;
    while (ub - lb > 1) {
      LL mid = (ub + lb) / 2;
      LL tm = Arui[i] + Brui[mid];
      if (tm <= K) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    tmp += lb;
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
  LL N, M, K;
  cin >> N >> M >> K;
  vector<LL> A(N);
  vector<LL> B(M);
  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];

  vector<LL> Arui(N + 1);
  vector<LL> Brui(N + 1);
  Arui[0] = 0;
  Brui[0] = 0;
  rep(i, N) { Arui[i + 1] = Arui[i] + A[i]; }
  rep(i, M) { Brui[i + 1] = Brui[i] + B[i]; }

  LL ans = 0;
  rep(i, N + 1) {
    LL tmp = 0;
    LL lim = K - Arui[i];
    if (lim < 0)
      continue;
    tmp = i;
    LL lb = 0;
    LL ub = M;
    while (ub - lb > 1) {
      LL mid = (ub + lb) / 2;
      LL tm = Arui[i] + Brui[mid];
      if (tm <= K) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    tmp += lb;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}