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

// Hail god Yato

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

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> fst(n), snd(m);
  for (int i = 0; i < n; i++)
    cin >> fst[i];
  for (int i = 0; i < m; i++)
    cin >> snd[i];
  ll ans = -1, f = 0, s = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (cnt + fst[i] > k)
      break;
    ++f;
    cnt += fst[i];
  }
  for (int i = 0; i < m; i++) {
    if (cnt + snd[i] > k)
      break;
    ++s;
    cnt += snd[i];
  }
  // cout<<s;
  ans = max(ans, f + s);
  for (int i = f - 1; i >= 0; i--) {
    cnt -= fst[i];
    while (s < m && cnt + snd[s] <= k) {
      cnt += snd[s];
      ++s;
      ans = max(i + s, ans);
    }
  }
  cout << ans;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

// Hail god Yato

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

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> fst(n), snd(m);
  for (int i = 0; i < n; i++)
    cin >> fst[i];
  for (int i = 0; i < m; i++)
    cin >> snd[i];
  ll ans = -1, f = 0, s = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (cnt > k)
      break;
    ++f;
    cnt += fst[i];
  }
  for (int i = 0; i < m; i++) {
    if (cnt > k)
      break;
    ++s;
    cnt += snd[s];
  }
  ans = max(ans, f + s);
  for (int i = f - 1; i >= 0; i--) {
    cnt -= fst[i];
    if (cnt + snd[s] <= k) {
      cnt += snd[s];
      ++s;
      ans = max(i + s, ans);
    }
  }
  cout << ans;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

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];
  ll iterA = 0;
  ll iterB = 0;
  ll ans = 0;
  while (a[iterA] <= k) {
    k -= a[iterA];
    iterA++;
    // cout << iterA << ":" << iterB << ":k=" << k << endl;

    if (iterA == n)
      break;
  }

  while (b[iterB] <= k) {
    k -= b[iterB];
    iterB++;
    // cout << iterA << ":" << iterB << ":k=" << k << endl;

    if (iterB == m) {
      cout << iterA + iterB << endl;
      return 0;
    }
  }

  ans = iterA + iterB;

  for (; iterA > 0; iterA--) {
    k += a[iterA - 1];
    while (b[iterB] <= k) {
      k -= b[iterB];
      iterB++;
      if (iterB == m)
        break;
    }
    // cout << iterA << ":" << iterB << ":k=" << k << endl;
    ans = max(iterA - 1 + iterB, ans);
    if (iterB == m)
      break;
  }

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

Error: 0

Fixed submission:

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

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];
  ll iterA = 0;
  ll iterB = 0;
  ll ans = 0;
  while (a[iterA] <= k) {
    k -= a[iterA];
    iterA++;
    // cout << iterA << ":" << iterB << ":k=" << k << endl;

    if (iterA == n)
      break;
  }

  while (b[iterB] <= k) {
    k -= a[iterB];
    iterB++;
    // cout << iterA << ":" << iterB << ":k=" << k << endl;

    if (iterB == m) {
      cout << iterA + iterB << endl;
      return 0;
    }
  }

  ans = iterA + iterB;

  for (; iterA > 0; iterA--) {
    k += a[iterA - 1];
    while (b[iterB] <= k) {
      k -= b[iterB];
      iterB++;
      if (iterB == m)
        break;
    }
    // cout << iterA << ":" << iterB << ":k=" << k << endl;
    ans = max(iterA + iterB, ans);
    if (iterB == m)
      break;
  }

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

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

const long long INF = 1e17 + 7;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1, 0), b(m + 1, 0);
  for (int i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    a[i] = temp + a[i - 1];
  }
  cout << endl;
  for (int i = 1; i <= m; i++) {
    int temp;
    cin >> temp;
    b[i] = temp + b[i - 1];
  }
  cout << endl;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    long long sum = a[i];
    if (sum > k)
      break;
    long long target = k - sum;
    int start = 0;
    int end = b.size();
    int now = (end + start) / 2;
    while (1) {
      if (b[now] == target)
        break;
      if (b[now] > target) {
        end = now;
      } else if (b[now] < target) {
        start = now;
      }
      now = (end + start) / 2;
      if (end - start <= 1)
        break;
    }
    ans = max(ans, now + i);
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

const long long INF = 1e17 + 7;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<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 cnt = 0;
  long long ans = 0;
  while (1) {
    if (a.size() == 0 && b.size() == 0)
      break;
    if (a[0] > k && b[0] > k)
      break;
    if (a.size() == 0 || a[0] > b[0]) {
      cnt += b[0];
      // cout << b[0] << endl;
      ans++;
      b.erase(b.begin());
      if (cnt >= k)
        break;
    } else {
      cnt += a[0];
      // cout << a[0] << endl;
      ans++;
      a.erase(a.begin());
      if (cnt >= k)
        break;
    }
  }
  if (cnt > k)
    ans--;
  cout << ans << endl;

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

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

using ll = long long;

using namespace std;

int main() {

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);

  for (ll i = 1; i <= n; i++) {
    ll input;
    cin >> input;
    a[i] = input + a[i - 1];
  }

  for (ll i = 1; i <= m; i++) {
    ll input;
    cin >> input;
    b[i] = input + b[i - 1];
  }

  ll ans = 0;
  ll mx = m;
  for (ll i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    while (b[mx] + a[i] > k) {
      mx--;
    }
    ans = max(ans, i + mx);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

using ll = long long;

using namespace std;

int main() {

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);

  for (ll i = 1; i <= n; i++) {
    ll input;
    cin >> input;
    a[i] = input + a[i - 1];
  }

  for (ll i = 1; i <= m; i++) {
    ll input;
    cin >> input;
    b[i] = input + b[i - 1];
  }

  ll ans = 0;
  ll mx = m;
  for (ll i = 0; i <= n; i++) {
    while (1) {
      if (b[mx] + a[i] > k) {
        mx--;
      } else {
        ans = max(ans, mx + i);
        break;
      }
      if (mx <= 0) {
        ans = max(ans, mx + i);
        break;
      }
    }
  }
  cout << ans << endl;

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m, k, ans = 0;
  cin >> n >> m >> k;
  ll a[n + 1], b[n + 1];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));

  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (ll i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  for (ll i = 0; i <= n; i++)
    if (k >= a[i])
      ans = max(ans, upper_bound(b + 1, b + 1 + m, k - a[i]) - b - 1 + i);
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  map<long long int, int, greater<int>> A;
  long long int n, m, k;
  cin >> n >> m >> k;
  long long int a;
  long long int s = 0;
  long long int ind1 = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    s += a;
    if (s <= k) {
      ind1 = i + 1;
      A.insert(make_pair(s, i + 1));
    }
  }
  long long int ind2 = 0;
  s = 0;
  long long int x;

  long long int j;
  for (long long int i = 0; i < m; i++) {
    cin >> a;
    s += a;
    if (s <= k) {
      ind2 = i + 1;
      x = k - s;
      auto it = A.lower_bound(x);
      if (it == A.end())
        continue;
      j = it->second + i + 1;
      if (j > ind1)
        ind1 = j;
    }
    // else break;
  }
  cout << max(ind1, ind2);
}


Error: WA

Fixed submission:

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

#define ll long long
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int MAX = 1e5 + 5;

int main() {
  IOS int t = 1;
  // cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int a[n + 1], b[m + 1];
    ll as[n + 1], bs[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
      cin >> b[i];
    }

    as[1] = a[1], bs[1] = b[1];
    for (int i = 2; i <= n; i++) {
      as[i] = as[i - 1] + a[i];
    }
    for (int i = 2; i <= m; i++) {
      bs[i] = bs[i - 1] + b[i];
    }
    int ct = 0, minm = min(n, m), pos = -1;
    for (int i = minm; i >= 1; i--) {
      if (min(as[i], bs[i]) <= k) {
        ct = i;
        k -= min(as[i], bs[i]);
        pos = i;
        break;
      }
    }

    if (pos > -1) {
      if (as[pos] < bs[pos]) {
        for (int i = 1; i <= m; i++) {
          if (k >= b[i]) {
            ct += 1;
            k -= b[i];
          } else
            break;
        }
      } else if (bs[pos] < as[pos]) {
        for (int i = 1; i <= n; i++) {
          if (k >= a[i]) {
            ct += 1;
            k -= a[i];
          } else
            break;
        }
      } else {
        int ct1 = 0, ct2 = 0;
        for (int i = 1; i <= n; i++) {
          if (k >= a[i]) {
            ct1 += 1;
            k -= a[i];
          } else
            break;
        }
        for (int i = 1; i <= m; i++) {
          if (k >= b[i]) {
            ct2 += 1;
            k -= b[i];
          } else
            break;
        }
        ct += max(ct1, ct2);
      }
    }
    cout << ct;
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> func(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

int main() {
  int64_t N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N);
  vector<int> B(M);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t sumb = 0;
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    sumb += B[i];
  }
  int ans = 0, j = M;
  for (int i = 0; i <= N; i++) {
    while (j > 0 && sumb > K) {
      j--;
      sumb -= B[j];
    }
    if (sumb > K) {
      break;
    }
    ans = max(ans, i + j);
    if (i == N) {
      break;
    }
    sumb += A[i];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> func(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

int main() {
  int64_t N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N + 1);
  vector<int> B(M + 1);
  int c = 0, k = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (c + A[i] <= K) {
      k = i;
    }
    c += A[i];
  }
  int r = 0, e = 0;
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    if (r + B[i] <= K) {
      e = i;
    }
    r += B[i];
  }
  // cout<<A[0]<<B[0]<<endl;
  int64_t suma = 0, ans = 0;
  for (int64_t i = 0; i <= k; i++) {
    suma += A[i];
    int64_t sumb = 0;
    for (int64_t j = 0; j <= e; j++) {
      sumb += B[j];
      if (suma + sumb <= K) {
        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 rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
  ll N, M, K, r, c = 0;
  cin >> N >> M >> K;
  r = M;

  vector<ll> A(N + 1, 0), B(M + 1, 0);
  rep(i, N) {
    cin >> A.at(i + 1);
    A.at(i + 1) += A.at(i);
  }
  rep(i, M) {
    cin >> B.at(i + 1);
    B.at(i + 1) += B.at(i);
  }

  rep(i, N + 1) {
    if (A.at(i) > K)
      break;
    for (int j = r; j >= 0; --j)
      if (B.at(j) <= K - A.at(i)) {
        r = j;
        break;
      }
    c = max(c, i + r);
  }

  cout << c << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll N, M, K, t = 0, a = 0, b = 0, c = 0;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M);

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

  while (1) {
    if (a == N && b == M) {
      cout << c << endl;
      return 0;
    }

    if (a == N) {
      t = B.at(b);
      ++b;
    } else if (b == N) {
      t += A.at(a);
      ++a;
    } else {
      if (A.at(a) < B.at(b))
        t += A.at(a++);
      else
        t += B.at(b++);
    }

    // cout << t << endl;

    if (t < K)
      ++c;
    else
      break;
  }

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

#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

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

  for (ll i = 1; i < M + 1; i++) {
    cin >> B[i];
    B[i] += B[i - 1];
  }
  ll ans = 0;
  ll time = 0;
  ll resi_time = K;
  ll B_i = 0;
  for (int i = N; i >= 0; i--) {
    time = A[i];
    if (time > K) {
      continue;
    }
    resi_time = K - time;
    for (ll j = B_i; j <= M; j++) {
      if (B[j] > resi_time) {
        break;
      }
      ans = max(ans, i + j);
      B_i = j;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

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

  for (ll i = 1; i < M + 1; i++) {
    cin >> B[i];
    B[i] += B[i - 1];
  }
  ll ans = 0;
  ll time = 0;
  ll resi_time = K;
  for (int i = N; i >= 0; i--) {
    time = A[i];
    if (time > K) {
      continue;
    }
    resi_time = K - time;
    for (ll j = M; j > ans - i; j--) {
      if (j < 0) {
        break;
      }
      if (B[j] > resi_time) {
        continue;
      }
      ans = max(ans, i + j);
      break;
    }
  }

  cout << ans << endl;

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

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

  cin >> N >> M >> K;
  A.resize(N + 1, 0);
  B.resize(M + 1, 0);
  int maxCountB = 0;
  int maxCountA = 0;
  for (int i = 1; i <= N; i++) {
    int a;
    cin >> a;
    A[i] = a + A[i - 1];
    if (A[i] <= K) {
      maxCountA = i;
    }
  }

  for (int i = 1; i <= M; i++) {
    int b;
    cin >> b;
    B[i] = b + B[i - 1];
    if (B[i] <= K) {
      maxCountB = i;
    }
  }
  int result = 0;
  for (int i = 0; i <= maxCountA; i++) {
    for (int j = maxCountB; j >= 0; j--) {
      if (A[i] + B[j] <= K) {
        result = max(result, i + j);
        maxCountB = j;
        break;
      }
    }
  }
  cout << result << endl;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  long long N, M, K;
  vector<long long> A, B;
  map<long long, long long> leftTimeToNumber;

  cin >> N >> M >> K;
  A.resize(N + 1, 0);
  B.resize(M + 1, 0);
  long long maxCountB = 0;
  long long countB = 0;
  leftTimeToNumber[0] = 0;
  for (long long i = 1; i <= N; i++) {
    long long a;
    cin >> a;
    A[i] = a + A[i - 1];
    leftTimeToNumber[A[i]] = i;
  }
  long long result = 0;
  long long count = 0;
  for (long long i = 1; i <= M; i++) {
    long long b;
    cin >> b;
    B[i] = b + B[i - 1];
    if (B[i] <= K) {
      maxCountB = i;
    }
  }
  for (long long i = 0; i <= maxCountB; i++) {
    long long left = max(K - B[(int)i], 0ll);
    while (!leftTimeToNumber.count(left)) {
      left--;
    }
    count = i + leftTimeToNumber[left];
    result = max(count, result);
  }
  cout << result << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok ? "Yes" : "No");
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  rep(i, n) cin >> a[i + 1];
  rep(i, n) a[i + 1] += a[i];
  rep(i, m) cin >> b[i + 1];
  rep(i, m) b[i + 1] += b[i];
  int ans = 0;
  int ptr = m;
  rep(i, n + 1) {
    int num = i;
    int rest = k - a[i];
    while (ptr >= 0 && rest < b[ptr])
      ptr--;
    if (ptr < 0)
      break;
    num += ptr;
    chmax(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok ? "Yes" : "No");
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  rep(i, n) cin >> a[i + 1];
  rep(i, n) a[i + 1] += a[i];
  rep(i, m) cin >> b[i + 1];
  rep(i, m) b[i + 1] += b[i];
  int ans = 0;
  int ptr = m;
  rep(i, n + 1) {
    int num = i;
    int rest = k - a[i];
    while (rest < b[ptr])
      ptr--;
    num += ptr;
    chmax(ans, num);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<long long> A(N);
  vector<long long> B(M);

  vector<long long> A_sum(N + 1);
  vector<long long> B_sum(M + 1);

  A_sum.at(0) = 0;
  B_sum.at(0) = 0;

  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
    A_sum.at(i + 1) = A_sum.at(i) + A.at(i);
    // cout << A_sum.at(i+1) << endl;
  }
  for (long long i = 0; i < M; i++) {
    cin >> B.at(i);
    B_sum.at(i + 1) = B_sum.at(i) + B.at(i);
  }

  long long sum = 0;
  long long sum_max = -1;
  long long last_j = 0;

  for (long long i = 0; i <= N; i++) {
    for (long long j = last_j; j <= M; j++) {
      if (A_sum.at(N - i) + B_sum.at(j) <= K) {
        sum = A_sum.at(N - i) + B_sum.at(j);
        last_j = j;
        if (sum_max < N - i + j) {
          sum_max = N - i + j;
        }
      } else {
        break;
      }
    }
  }

  cout << sum_max << endl;
}


Error: TLE

Fixed submission:

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

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

  vector<long long> A(N);
  vector<long long> B(M);

  vector<long long> A_sum(N + 1);
  vector<long long> B_sum(M + 1);

  A_sum.at(0) = 0;
  B_sum.at(0) = 0;

  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
    A_sum.at(i + 1) = A_sum.at(i) + A.at(i);
    // cout << A_sum.at(i+1) << endl;
  }
  for (long long i = 0; i < M; i++) {
    cin >> B.at(i);
    B_sum.at(i + 1) = B_sum.at(i) + B.at(i);
  }

  long long sum = 0;
  long long sum_max = -1;

  for (long long i = 0; i <= N; i++) {
    for (long long j = 0; j <= M; j++) {
      if (A_sum.at(N - i) + B_sum.at(j) <= K) {
        sum = A_sum.at(N - i) + B_sum.at(j);
        if (sum_max < N - i + j) {
          sum_max = N - i + j;
        }
      } else {
        break;
      }
    }
  }

  cout << sum_max << endl;
}