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

#include <bits/stdc++.h>
#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z, a, b) vector<vector<int>> z(a, vector<int>(b))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) begin(c), end(c)
#define pp pair<int, int>
#define fix(n) fixed << setprecision(n)
#define gmax(a, b) __gcd(a, b)
#define gmin(a, b) a / __gcd(a, b) * b
using namespace std;

int main() {

  int n, m, k;
  cin >> n >> m >> k;
  vll a(n + 1);
  vll b(m + 1);
  rep(i, n + 1) {
    ll an = 0;

    if (i == 0)
      a.at(i) = 0;
    else {
      cin >> an;
      a.at(i) = a.at(i - 1) + an;
    }
  }
  rep(i, m + 1) {
    int an = 0;
    if (i == 0)
      b.at(i) = 0;
    else {
      cin >> an;
      b.at(i) = b.at(i - 1) + an;
    }
  }
  ll sum = 0;
  ll ans = 0;
  int ko = 0;
  rep(i, n + 1) {
    for (int j = m; j >= 0; --j) {
      sum = a.at(i) + b.at(j);
      if (sum <= k) {
        ll anti = i + j;
        ans = max(ans, anti);
        m = j;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z, a, b) vector<vector<int>> z(a, vector<int>(b))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) begin(c), end(c)
#define pp pair<int, int>
#define fix(n) fixed << setprecision(n)
#define gmax(a, b) __gcd(a, b)
#define gmin(a, b) a / __gcd(a, b) * b
using namespace std;

int main() {

  int n, m, k;
  cin >> n >> m >> k;
  vll a(n + 1);
  vll b(m + 1);
  rep(i, n + 1) {
    ll an = 0;

    if (i == 0)
      a.at(i) = 0;
    else {
      cin >> an;
      a.at(i) = a.at(i - 1) + an;
    }
  }
  rep(i, m + 1) {
    int an = 0;
    if (i == 0)
      b.at(i) = 0;
    else {
      cin >> an;
      b.at(i) = b.at(i - 1) + an;
    }
  }
  ll sum = 0;
  ll ans = 0;
  rep(i, n + 1) {
    rep(j, m + 1) {
      sum = a.at(i) + b.at(j);
      if (sum <= k) {
        ll ansi = i + j;
        ans = max(ans, ansi);
      } else
        break;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  long sum_A[N + 1];
  sum_A[0] = 0;
  for (int i = 1; i <= N; i++) {
    int A;
    cin >> A;
    sum_A[i] = sum_A[i - 1] + A;
  }
  long sum_B[M + 1];
  sum_B[0] = 0;
  for (int i = 1; i <= M; i++) {
    int B;
    cin >> B;
    sum_B[i] = sum_B[i - 1] + B;
  }
  int ans = -1;
  int prev_j = M;
  for (int i = 0; i <= N; i++) {
    long for_B = K - sum_A[i];
    for (int j = prev_j; j >= 0; j--) {
      if (sum_B[j] <= for_B) {
        ans = max(ans, i + j);
        prev_j = j;
        break;
      }
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  long sum_A[N + 1];
  sum_A[0] = 0;
  for (int i = 1; i <= N; i++) {
    int A;
    cin >> A;
    sum_A[i] = sum_A[i - 1] + A;
  }
  long sum_B[M + 1];
  sum_B[0] = 0;
  for (int i = 1; i <= M; i++) {
    int B;
    cin >> B;
    sum_B[i] = sum_B[i - 1] + B;
  }
  int ans = -1;
  for (int i = 0; i <= N; i++) {
    long for_B = K - sum_A[i];
    for (int j = M; j >= 0; j--) {
      if (sum_B[j] <= for_B) {
        ans = max(ans, i + j);
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  int m = 1;
  while (m < M)
    m *= 2;
  vector<int> A(N + 1), B(M + 1);
  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 l = 0;
  for (int i = N; i >= 0; i--) {
    int j = upper_bound(B.begin(), B.end(), K - A[i]) - B.begin();
    if (j == M + 1)
      l = max(l, i + M);
    else if (j != 0 || A[i] < K)
      l = max(l, i + j - 1);
  }
  cout << l << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  int m = 1;
  while (m < M)
    m *= 2;
  vector<int> A(N + 1), B(M + 1);
  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 l = 0;
  for (int i = N; i >= 0; i--) {
    int j = m / 4, k = M / 2;
    while (j > 0) {
      if (A[i] + B[k] < K)
        k += j;
      else
        k -= j;
      j = j / 2;
    }
    if (0 <= k + 2 && k + 2 <= M && A[i] + B[k + 2] <= K)
      l = max(l, i + k + 1);
    else if (0 <= k + 1 && k + 1 <= M && A[i] + B[k + 1] <= K)
      l = max(l, i + k + 1);
    else if (0 <= k && k <= M && A[i] + B[k] <= K)
      l = max(l, i + k);
    else if (0 <= k - 1 && k - 1 <= M && A[i] + B[k - 1] <= K)
      l = max(l, i + k - 1);
    else if (0 <= k - 2 && k - 2 <= M && A[i] + B[k - 2] <= K)
      l = max(l, i + k - 1);
  }
  cout << l << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  for (int &x : a)
    cin >> x;
  for (int &x : b)
    cin >> x;
  int i = 0, j = 0;
  while (i < n && k - a[i] > 0) {
    k -= a[i++];
  }
  int ans = i;
  for (int j = 0; j < m; j++) {
    if (a[j] > k)
      break;
    while (i > 0 && k - a[j] < 0) {
      i--;
      k = k + a[i];
    }
    k = k - a[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;

using Graph = vector<vector<long long>>;

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

  vector<long long> A;
  vector<long long> B;
  vector<long long> Sa(N + 1);
  vector<long long> Sb(M + 1);
  int a, b;
  int amax, bmax;
  int result = 0;
  for (int i = 1; i <= N; i++) {
    cin >> a;
    A.push_back(a);
    Sa[i] = Sa[i - 1] + a;
    if (Sa[i] > K) {
      amax = i - 1;
    }
  }
  long long t = 0;
  for (int i = 1; i <= M; i++) {
    cin >> b;
    B.push_back(b);
    t += b;
    Sb[i] = Sb[i - 1] + b;
    if (Sb[i] > K) {
      bmax = i - 1;
    }
  }

  int j = M;
  for (int i = 0; i < N + 1; i++) {
    while (j > 0 && t > K) {
      j--;
      t -= B[j];
    }
    if (t > K) {
      break;
    }
    result = max(result, i + j);
    if (i == N) {
      break;
    }
    t += A[i];
  }

  cout << result << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  stack<long long> A;
  stack<long long> B;
  int a, b;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.push(a);
  }
  for (int i = 0; i < M; i++) {
    cin >> b;
    B.push(b);
  }

  long long t = 0;
  int result = 0;
  while (1) {
    if (t + A.top() > K && t + B.top() > K) {
      break;
    }
    if (A.top() >= B.top()) {
      t += B.top();
      B.pop();
      result++;
    } else {
      t += A.top();
      A.pop();
      result++;
    }
  }
  cout << result << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, M, K;
  std::cin >> N >> M >> K;
  std::vector<unsigned long long> A, B;
  A.resize(N + 1);
  for (int i = 0; i < N; i++) {
    int tmp;
    std::cin >> tmp;
    A[i + 1] = A[i] + tmp;
  }
  B.resize(M + 1);
  for (int i = 0; i < M; i++) {
    int tmp;
    std::cin >> tmp;
    B[i + 1] = B[i] + tmp;
  }
  int max = 0;
  int an = std::upper_bound(A.begin(), A.end(), K) - A.begin() - 1;
  for (int i = an; i >= 0; i--) {
    int j = std::upper_bound(B.begin(), B.end(), K - A[i]) - B.begin();
    max = std::max(max, i + j - 1);
  }
  std::cout << max << std::endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, M, K;
  std::cin >> N >> M >> K;
  std::vector<unsigned long long> A, B;
  A.resize(N + 1);
  for (int i = 0; i < N; i++) {
    int tmp;
    std::cin >> tmp;
    A[i + 1] = A[i] + tmp;
  }
  B.resize(M + 1);
  for (int i = 0; i < M; i++) {
    int tmp;
    std::cin >> tmp;
    B[i + 1] = B[i] + tmp;
  }
  int max = 0;
  int an = std::upper_bound(A.begin(), A.end(), K) - A.begin();
  for (int i = 0; i < an; i++) {
    int j;
    for (j = 0; j < B.size(); j++) {
      if (A[i] + B[j] > K)
        break;
    }
    max = std::max(max, i + j - 1);
  }
  std::cout << max << std::endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll 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[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  ll ans = 0, j = m;
  for (ll i = 0; i <= n; i++) {
    if (a[i] > k)
      continue;
    while (b[j] > k - a[i])
      j -= 1;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long long k, n, m;
  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];

  long long ans = 0, sum = 0;
  long long i = 0, j = 0;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  while (sum + a[i] < k) {
    if (i < n) {
      sum += a[i];
      ans++;
    }
    if (sum + b[j] <= k && j < m) {
      sum += b[j];
      ans++;
    }
    i++, j++;
  }
  cout << ans << endl;
  return 0;
}
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;
  vector<int> a(n);
  vector<int> b(m);

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

  long long t = 0;
  for (int i = 0; i < m; i++) {
    t += b[i];
  }

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

Error: 0

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(n);

  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }

  long long time = 0;
  long long ans = 0;
  long long j = 0;

  for (long long i = 0; i < m; i++) {
    cin >> b[i];

    while (b[i] > a[j] && time < k && j < n) {
      time += a[j];
      j++;
      ans++;
    }

    if (time < k) {
      time += b[i];
      ans++;
    }

    if (time >= k) {
      break;
    }
  }

  if (time <= k) {
    cout << ans << endl;
  } else {
    cout << ans - 1 << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (i = 1; i <= n; i++)
// 2D::rep(i,j)rep(j,j)cin>>bin[i][j];
// vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout << "No" << endl
#define A2 cout << "Yes" << endl
#define A3 cout << ans <<
#define AA(i) cout << i << endl;
const int U = 2e5 + 5;
const ll MOD = 1000000007;
const int INF = 1001001001;

bool isOK(int index, int key, vector<ll> &B) {
  if (B[index] > key)
    return true;
  else
    return false;
}
int binary_search(int key, vector<ll> &B) {
  int left = -1;
  int right = (int)B.size();
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (isOK(mid, key, B))
      right = mid;
    else
      left = mid;
  }
  return right - 1;
}

int main() {
  int i, N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> A(N + 1), B(M + 1);
  A[0] = 0;
  B[0] = 0;
  ll a;
  int n, m;
  rep(i, N) {
    cin >> a;
    if (A[i - 1] <= K) {
      A[i] = a + A[i - 1];
    } else {
      A[i] = A[i - 1];
    }
  }
  rep(i, M) {
    cin >> a;
    if (B[i - 1] <= K) {
      B[i] = a + B[i - 1];
    } else {
      B[i] = B[i - 1];
    }
  }

  int ans = 0;
  int k;
  for (i = 0; i <= N; i++) {
    if (A[i] > K)
      break;
    k = binary_search(K - A[i], B);
    ans = max(ans, k + i);
  }
  AA(ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (i = 1; i <= n; i++)
// 2D::rep(i,j)rep(j,j)cin>>bin[i][j];
// vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout << "No" << endl
#define A2 cout << "Yes" << endl
#define A3 cout << ans <<
#define AA(i) cout << i << endl;
const int U = 2e5 + 5;
const ll MOD = 1000000007;
const int INF = 1001001001;

bool isOK(int index, int key, vector<ll> B) {
  if (B[index] > key)
    return true;
  else
    return false;
}
int binary_search(int key, vector<ll> B) {
  int left = -1;
  int right = (int)B.size();
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (isOK(mid, key, B))
      right = mid;
    else
      left = mid;
  }
  return right - 1;
}

int main() {
  int i, N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> A(N + 1), B(M + 1);
  A[0] = 0;
  B[0] = 0;
  ll a;
  int n, m;
  rep(i, N) {
    cin >> a;
    if (A[i - 1] <= K) {
      A[i] = a + A[i - 1];
    } else {
      A[i] = A[i - 1];
    }
  }
  rep(i, M) {
    cin >> a;
    if (B[i - 1] <= K) {
      B[i] = a + B[i - 1];
    } else {
      B[i] = B[i - 1];
    }
  }

  int ans = 0;
  int k;
  for (i = 0; i <= N; i++) {
    if (A[i] > K)
      break;
    k = binary_search(K - A[i], B);
    ans = max(ans, k + i);
  }
  AA(ans);
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

ull a[200001], b[200001];

int main() {
  IOS;
  ull n, m, k, i = 0, j = 0, time = 0, count = 0;
  ;
  cin >> n >> m >> k;
  for (ull x = 0; x < n; x += 1) {
    cin >> a[x];
  }
  for (ull x = 0; x < m; x += 1) {
    cin >> b[x];
  }
  while (i < n && time + a[i] <= k) {
    time += a[i++];
  }
  count = i;
  while (j < m && i >= 0) {
    time += b[j++];
    while (time > k && i > 0) {
      i--;
      time -= a[i];
    }
    if (time <= k && i + j > count) {
      count = i + j;
    }
  }
  cout << count << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

ull a[200001], b[200001];

int main() {
  IOS;
  ull n, m, k, i = 0, j = 0, time = 0, count = 0;
  ;
  cin >> n >> m >> k;
  for (ull x = 0; x < n; x += 1) {
    cin >> a[x];
  }
  for (ull x = 0; x < m; x += 1) {
    cin >> b[x];
  }
  for (ull x = 0; x < n + m; x += 1) {
    ull temp = min(a[i], b[j]);
    if (temp == a[i])
      i += 1;
    else
      j += 1;
    if (time + temp < k) {
      time += temp;
      count += 1;
    } else {
      break;
    }
  }
  cout << count << 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++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

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

  ll ans = 0, j = 0;
  rep(i, n + 1) {
    if (a[i] > k)
      break;
    ll lb = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();

    lb--;
    // cout << a[i] << " " << lb +i<< endl;
    ans = max(ans, lb + i);
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

ll n, m, k;
vector<int> a(n + 2), b(m + 2);
ll ans = 0;

void bfs(ll k, ll aa, ll bb, ll cnt) {
  if (k < a[aa] || k < b[bb])
    return;
  if (aa == n || bb == m)
    return;
  ans = max(ans, cnt);
  bfs(k - a[aa], aa + 1, bb, cnt + 1);
  bfs(k - b[bb], aa, bb + 1, cnt + 1);
}

int main() {
  cin >> n >> m >> k;
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  bfs(k - a[0], 1, 0, 0);
  bfs(k - b[0], 0, 1, 0);

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


#include <bits/stdc++.h>

using namespace std;

#define fstinpt ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define sn 1010
#define bn 10000007
#define M 1000000007
#define cin(i) cin >> i
#define cout(i) cout << i
#define sss cout << " "
#define nnn cout << "\\n"

ll sa[bn], sb[bn];

int main() {
  fstinpt;
  ll a, b, k, ma, mb;
  bool o1 = 1, o2 = 1;
  cin(a >> b >> k);
  for (ll i = 1; i <= a; i++) {
    cin(sa[i]);
    sa[i] += sa[i - 1];
    if (sa[i] > k and o1) {
      o1 = 0;
      ma = i - 1;
    }
  } // cumulative sum A array er
  for (ll i = 1; i <= b; i++) {
    cin(sb[i]);
    sb[i] += sb[i - 1];
    if (sb[i] > k and o2) {
      o2 = 0;
      mb = i - 1;
    }
  } // cumulative sum B array er
  if (sa[a] <= k and sb[b] <= k and sa[a] + sb[b] <= k) {
    cout(a + b);
    return 0;
  }
  if (sa[a] <= k and sb[b] <= k and sa[a] + sb[b] > k) {
    ma = a;
    mb = b;
  }
  if (o1)
    ma = a;
  if (o2)
    mb = b;
  ll jj = ma;
  for (ll i = 0; i <= ma; i++) {
    for (ll j = jj - ma + i + 1; sa[ma - i] + sb[j] <= k and j <= mb; j++) {
      jj = ma - i + j;
      //                        cout(sa[ma-i]+sb[j]<<" "<<jj<<"
      //                        "<<sa[ma-i]<<"+"<<sb[j]<<" "<<ma-i<<"+"<<j);nnn;
    }
  }
  cout(jj);
  return 0;
}


Error: -11

Fixed submission:



#include <bits/stdc++.h>

using namespace std;

#define fstinpt ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define sn 1010
#define bn 10000007
#define M 1000000007
#define iii(i) cin >> i
#define ooo(i) cout << i
#define sss cout << " "
#define nnn cout << "\\n"

ll aa[bn], bb[bn];

int main() {
  ll a, b, k;
  iii(a >> b >> k);
  for (ll i = 0; i < a; i++)
    iii(aa[i]);
  for (ll i = 0; i < b; i++)
    iii(bb[i]);
  aa[a] = 0;
  bb[b] = 0;
  ll pa = 0, pb = 0, i;
  for (i = 0;; i++) {
    if (aa[pa] == 0 and bb[pb] > 0 and bb[pb] <= k) {
      k -= bb[pb];
      pb++;
      if (k == 0) {
        i++;
        break;
      }
      continue;
    }
    if (aa[pa] > 0 and bb[pb] == 0 and aa[pa] <= k) {
      k -= aa[pa];
      pa++;
      if (k == 0) {
        i++;
        break;
      }
      continue;
    }
    if (aa[pa] > k and bb[pb] > k)
      break;
    if (k == 0)
      break;
    if (aa[pa] > bb[pb]) {
      k -= bb[pb];
      pb++;
      continue;
    }
    if (aa[pa] <= bb[pb]) {
      k -= aa[pa];
      pa++;
      continue;
    }
  }
  ooo(i);
  return 0;
}

/*

3 4 240
60 90 120
80 150 80 150

3 4 730
60 90 120
80 150 80 150


                ooo("k = "<<k);nnn;
*/

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

#include <cassert>
#include <cmath>
#include <iostream>
#include <stack>
#include <stdexcept>
#include <vector>
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++) {
    cin >> A[i];
    A[i] += A[i - 1];
  }
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    B[i] += B[i - 1];
  }

  int ans = 0;
  long long life;
  int l, r, m;
  for (int i = 0; i <= N; i++) {
    life = K;
    life -= A[i];
    if (life < 0)
      break;
    l = 0;
    r = M;
    if (life - B[M] >= 0) {
      l = M;
      r = M + 1;
    }
    // l is ok, r is ng
    while (r > l + 1) {
      m = l + (r - l) / 2;
      if (life - B[m] >= 0)
        l = m;
      else
        r = m;
    }
    assert(life - B[l] >= 0);
    ans = max(ans, i + l);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cassert>
#include <cmath>
#include <iostream>
#include <stack>
#include <stdexcept>
#include <vector>
using namespace std;

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

  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1, -1));
  dp[0][0] = K;

  vector<int> B;
  int ans = 0;
  int x;
  for (int i = 1; i <= N; i++) {
    cin >> x;
    dp[i][0] = dp[i - 1][0] - x;
    if (dp[i][0] >= 0)
      ans = max(ans, i);
  }

  for (int j = 1; j <= M; j++) {
    cin >> x;
    dp[0][j] = dp[0][j] - x;
    B.push_back(x);
    if (dp[0][j] >= 0)
      ans = max(ans, j);
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      dp[i][j] = dp[i][j - 1] - B[j - 1];
      if (dp[i][j] < 0)
        break;
      ans = max(ans, i + j);
    }
  }

  cout << ans << endl;

  return 0;
}