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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 400005;
const ll INF = 1LL << 60;

int main() {

  std::ifstream in("text.txt");
  std::cin.rdbuf(in.rdbuf());
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> 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];
  }
  A.push_back(INF);
  B.push_back(INF);

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

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 400005;
const ll INF = 1LL << 60;

int main() {

  std::ifstream in("text.txt");
  std::cin.rdbuf(in.rdbuf());
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> 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];
  }
  A.push_back(INF);
  B.push_back(INF);

  int ans = 0;
  int j = N;
  for (int i = 0; i <= N; i++) {
    if (A[i] > K)
      break;
    while (j >= 0 && A[i] + B[j] > K)
      j--;
    chmax(ans, i + j);
  }

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n), 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> a2(n + 1), b2(m + 1);
  for (int i = 0; i < n; i++) {
    a2[i + 1] = a2[i] + a[i];
  }
  for (int i = 0; i < m; i++) {
    b2[i + 1] = b2[i] + b[i];
  }
  long long ans = 0;
  long long j = m;
  for (int i = 0; i < n + 1; i++) {
    if (a2[i] > k) {
      break;
    }
    while (b2[j] > k - a2[i]) {
      j -= 1;
    }
    ans = max(ans, i + j);
  }
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n), 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> ab(n + m);
  long long i1 = 0, i2 = 0;
  for (int i = 0; i < n + m; i++) {
    if (i % 2 == 0) {
      ab[i] = a[i1];
      ++i1;
    } else {
      ab[i] = b[i2];
      ++i2;
    }
  }
  long long cnt = 0;
  sort(ab.begin(), ab.end());
  int flag = 0;
  for (int i = 0; i < n + m; i++) {
    if (ab[i] <= k) {
      k -= ab[i];
      ++cnt;
    } else if (flag != 2) {
      ++flag;
      continue;
    } else {
      break;
    }
  }
  cout << cnt << '\\n';
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<ll, ll> P;

int main() {
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  int ans = 0, N = 0, M = 0;
  a[0] = 0;
  b[0] = 0;
  rep(i, n) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  rep(i, m) {
    cin >> b[i + 1];
    b[i + 1] += b[i];
  }
  int o = m;
  for (int i = 0; i <= n; i++) {
    while (a[i] + b[o] > k && o >= 0) {
      o--;
    }
    // cout<<ans<<endl;
    if (o >= 0)
      ans = max(ans, i + o);
    else
      break;
  }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<ll, ll> P;

int main() {
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  int ans = 0, N = 0, M = 0;
  a[0] = 0;
  b[0] = 0;
  rep(i, n) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  rep(i, m) {
    cin >> b[i + 1];
    b[i + 1] += b[i];
  }
  int o = m;
  for (int i = 0; i <= n; i++) {
    while (a[o] + b[i] > k && o >= 0) {
      o--;
    }
    // cout<<ans<<endl;
    if (o >= 0)
      ans = max(ans, i + o);
    else
      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;
typedef vector<long long> vll;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vll a(n), b(m), a_(n + 1, 0), b_(m + 1, 0);

  for (int ix = 0; ix < n; ix++) {
    cin >> a.at(ix);
    a_.at(ix + 1) = a.at(ix) + a_.at(ix);
  }
  for (int ix = 0; ix < m; ix++) {
    cin >> b.at(ix);
    b_.at(ix + 1) = b.at(ix) + b_.at(ix);
  }
  int cnt = 0, ixx = m;
  for (int ix = 0; ix <= n; ix++) {
    if (a_.at(ix) > k)
      break;
    while (ixx >= 0 && b_.at(ixx) + a_.at(ix) > k) {
      ixx--;
    }
    cnt = max(cnt, ix + ixx);
  }
  cout << cnt << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vll a(n), b(m), a_(n), b_(m);
  ll sum = 0;
  int amax = n;
  bool flag = false;
  for (int ix = 0; ix < n; ix++) {
    cin >> a.at(ix);
    sum += a.at(ix);
    a_.at(ix) = sum;
  }
  sum = 0;
  for (int ix = 0; ix < m; ix++) {
    cin >> b.at(ix);
    sum += b.at(ix);
    b_.at(ix) = sum;
  }
  int cnt = 0, ixx = m - 1;
  for (int ix = 0; ix < n; ix++) {
    if (a_.at(ix) > k)
      break;
    while (b_.at(ixx) + a_.at(ix) > k) {
      ixx--;
    }
    cnt = max(cnt, ix + ixx + 2);
  }
  cout << cnt << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define INF 10000000000

int main() {
  int n, m, i, j;
  long long k, ans = 0;
  cin >> n >> m >> k;
  vector<long long> a(n + 1), b(m + 1);
  a.at(0) = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a.at(i);
    a.at(i) += a[i - 1];
  }
  b.at(0) = 0;
  for (int i = 1; i < m + 1; i++) {
    cin >> b.at(i);
    b.at(i) += b[i - 1];
  }

  i = 0;
  j = m;
  while (i < a.size()) {
    if (a[i] > k)
      break;
    while (j > 0) {
      if (b[j] <= k - a[i])
        break;
      j--;
    }
    if (i + j > ans)
      ans = i + j;
    i++;
  }

  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define INF 10000000000

vector<long long> Compare(vector<long long> x, vector<long long> y, int xi,
                          int yi) {
  if (xi >= x.size() - 1)
    return y;
  if (xi >= x.size() - 1)
    return x;
  if (x[xi + 1] < y[yi + 1]) {
    return x;
  } else if (x[xi + 1] > y[yi + 1]) {
    return y;
  } else {
    return Compare(x, y, xi + 1, yi + 1);
  }
}

int main() {
  int n, m, ai = 0, bi = 0;
  long long k, sum = 0, ans = 0;
  cin >> n >> m >> k;
  vector<long long> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  a.push_back(INF);
  b.push_back(INF);

  while (sum <= k) {
    if (a[ai] == INF && b[bi] == INF) {
      ans++;
      break;
    }
    if (a[ai] < b[bi]) {
      ans++;
      sum += a[ai];
      ai++;
    } else if (a[ai] > b[bi]) {
      ans++;
      sum += b[bi];
      bi++;
    } else {
      if (Compare(a, b, ai, bi) == a) {
        ans++;
        sum += a[ai];
        ai++;
      } else {
        ans++;
        sum += b[bi];
        bi++;
      }
    }
  }
  ans--;

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

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main() {
  llong N, M, K;
  cin >> N >> M >> K;
  vector<llong> A(N);
  vector<llong> B(M);
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  for (int i = 0; i < M; ++i)
    cin >> B[i];
  llong countA = 0;
  llong countB = 0;
  llong time = 0;
  while (true) {
    if (A[countA] < B[countB]) {
      time += A[countA];
      ++countA;
    } else if (A[countA] > B[countB]) {
      time += B[countB];
      ++countB;
    } else {
      int a = countA;
      int b = countB;
      while (true) {
        ++a;
        ++b;
        if (A[a] < B[b]) {
          time += A[countA];
          ++countA;
          break;
        } else if (A[a] > B[b]) {
          time += B[countB];
          ++countB;
          break;
        }
      }
    }
    if (time > K)
      break;
  }
  cout << countA + countB - 1 << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <limits>
#include <math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
#define PI 3.141592653
#define rep(i, k, n) for (ll i = k; i < n; i++)

int main() {
  ll a, b, t;
  cin >> a >> b >> t;
  vll v1(a + 1, 0);
  vll v2(b + 1, 0);

  rep(i, 1, a + 1) {
    ll k;
    cin >> k;
    v1[i] = v1[i - 1] + k;
  }
  rep(i, 1, b + 1) {
    ll k;
    cin >> k;
    v2[i] = v2[i - 1] + k;
  }

  ll res = 0;
  ll cnt = 0;
  ll st = b;
  rep(i, 0, a + 1) {
    ll c = 0;
    for (ll j = st; j >= 0; j--) {
      if (v1[i] + v2[j] <= t) {
        c = i + j;
        st = j;
        break;
      }
    }
    cnt = max(c, cnt);
  }

  cout << cnt << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <limits>
#include <math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
#define PI 3.141592653
#define rep(i, k, n) for (ll i = k; i < n; i++)

int main() {
  ll a, b, t;
  cin >> a >> b >> t;
  vll v1(a + 1, 0);
  vll v2(b + 1, 0);

  rep(i, 1, a + 1) {
    ll k;
    cin >> k;
    v1[i] = v1[i - 1] + k;
  }
  rep(i, 1, b + 1) {
    ll k;
    cin >> k;
    v2[i] = v2[i - 1] + k;
  }

  ll res = 0;
  ll cnt = 0;
  rep(i, 0, a + 1) {
    ll c = 0;
    rep(j, 0, b + 1) {
      res = v1[i] + v2[j];
      if (res > t) {
        break;
      }
      c = i + j;
    }
    cnt = max(cnt, c);
  }

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

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

int main() {
  int N, M, max = 0, a = 0, b = 0;
  int64_t aT = 0, bT = 0, K;
  cin >> N >> M >> K;
  vector<int64_t> A(N), B(M);
  for (int64_t &x : A) {
    cin >> x;
  }
  for (int64_t &x : B) {
    cin >> x;
  }
  for (int i = 0; i < N; i++) {
    aT += A.at(i);
    a++;
    if (aT > K) {
      a--;
      aT -= A.at(a);
      break;
    }
  }
  do {
    for (int i = b; i < M; i++) {
      bT += B.at(i);
      b++;
      if (bT + aT > K) {
        b--;
        bT -= B.at(b);
        break;
      }
    }
    if (b == M && a == N) {
      max = a + b;
      break;
    }
    if (max < a + b) {
      max = a + b;
    }
    if (a != 0) {
      a--;
      aT -= A.at(a);
    } else {
      break;
    }
  } while (1);
  cout << max << endl;
}

Error: TLE

Fixed submission:

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

int read_book(vector<int> &A, vector<int> &B, int K, int a, int b, int t) {
  if (K < t) {
    return a + b - 1;
  }
  if (K == t) {
    return a + b;
  } else if (a > (int)A.size() || b > (int)B.size()) {
    return a + b - 1;
  }
  if (a == (int)A.size()) {
    return read_book(A, B, K, a, b + 1, t + B.at(b));
  } else if (b == (int)B.size()) {
    return read_book(A, B, K, a + 1, b, t + A.at(a));
  }
  return max(read_book(A, B, K, a + 1, b, t + A.at(a)),
             read_book(A, B, K, a, b + 1, t + B.at(b)));
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  cout << read_book(A, B, K, 0, 0, 0) << 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 INF 1000000007
using namespace std;

int main() {
  long n, m, k;
  cin >> n >> m >> k;
  long a[n], b[m];
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  long suma = 0, sumb = 0;
  long ka = 0, kb = 0;
  long ai = 0;
  rep(i, n) {
    if (ka + a[i] <= k) {
      suma++;
      ka += a[i];
      ai++;
    } else
      break;
  }
  long bi = 0;
  rep(i, m) {
    if (ka + b[i] <= k) {
      suma++;
      ka += b[i];
      bi++;
    } else
      break;
  }
  long ans = suma;
  long nsuma = suma;
  while (ai > 0) {
    ka -= a[ai - 1];
    ai -= 1;
    nsuma -= 1;
    while (ka + b[bi] <= k && bi < m) {
      ka += b[bi];
      nsuma += 1;
      bi++;
    }
    if (ans < nsuma)
      ans = nsuma;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long n, m, k;
  cin >> n >> m >> k;
  long a[n], b[n];
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  long suma = 0, sumb = 0;
  long ka = 0, kb = 0;
  long ai = 0;
  rep(i, n) {
    if (ka + a[i] <= k) {
      suma++;
      ka += a[i];
      ai++;
    } else
      break;
  }
  long bi = 0;
  rep(i, m) {
    if (ka + b[i] <= k) {
      suma++;
      ka += b[i];
      bi++;
    }
  }
  long ans = suma;
  long nsuma = suma;
  while (ai > 0) {
    ka -= a[ai - 1];
    ai -= 1;
    nsuma -= 1;
    while (ka + b[bi] <= k && bi < m) {
      ka += b[bi];
      nsuma += 1;
      bi++;
    }
    if (ans < nsuma)
      ans = nsuma;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0);
  vector<ll> a_sum(n + 1, 0);
  vector<ll> b(m + 1, 0);
  vector<ll> b_sum(m + 1, 0);

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a_sum[i] = a_sum[i - 1] + a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b_sum[i] = b_sum[i - 1] + b[i];
  }

  ll max_c = 0;
  ll i, j;
  j = m;
  for (i = 0; i <= n && a_sum[i] <= k; i++) {
    while (a_sum[i] + b_sum[j] > k) {
      j--;
    }
    if (i + j > max_c)
      max_c = i + j;
  }

  cout << max_c << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> a_sum(n + 1);
  vector<ll> b(m + 1);
  vector<ll> b_sum(m + 1);
  a[0] = 0;
  a_sum[0] = 0;
  b[0] = 0;
  b_sum[0] = 0;

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a_sum[i] = a_sum[i - 1] + a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b_sum[i] = b_sum[i - 1] + b[i];
  }

  ll t = 0;
  ll max_c = 0;
  ll i, j;
  for (i = 0; i <= n; i++) {
    if (a_sum[i] > k)
      break;
    t = 0;
    j = m;
    while (a_sum[i] + b_sum[j] > k) {
      j--;
    }
    if (i + j > max_c)
      max_c = i + j;
  }

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

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

int main() {
  /*ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);*/

  long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
      v, w, x, y, z;

  vector<long long int> v1, v2;

  cin >> n >> m >> k;

  s = 0;
  b = -1;
  c = -1;
  for (i = 0; i < n; i++) {
    cin >> a;
    s += a;
    if (s <= k)
      b = i;
    v1.push_back(s);
  }

  s = 0;
  for (i = 0; i < m; i++) {
    cin >> a;
    s += a;
    if (s <= k)
      c = i;
    v2.push_back(s);
  }

  m = 0;
  b = upper_bound(v2.begin(), v2.end(), k) - v2.begin();
  if (b > 0)
    m = max(m, b);
  for (i = 0; i < n && v1[i] <= k; i++) {
    b = upper_bound(v2.begin(), v2.end(), k - v1[i]) - v2.begin();
    if (b > 0)
      m = max(m, i + 1 + b);
    else
      m = max(m, i + 1);
  }

  cout << m << "\\n";

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  /*ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);*/

  long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
      v, w, x, y, z;

  vector<long long int> v1, v2;

  cin >> n >> m >> k;

  s = 0;
  b = -1;
  c = -1;
  for (i = 0; i < n; i++) {
    cin >> a;
    s += a;
    if (s <= k)
      b = i;
    v1.push_back(s);
  }

  s = 0;
  for (i = 0; i < m; i++) {
    cin >> a;
    s += a;
    if (s <= k)
      c = i;
    v2.push_back(s);
  }

  m = 0;
  for (i = 0; i < n && v1[i] <= k; i++) {
    b = upper_bound(v2.begin(), v2.end(), k - v1[i]) - v2.begin();
    if (b > 0)
      m = max(m, i + 1 + b);
    else
      m = max(m, i + 1);
  }
  for (i = 0; i < m && v2[i] <= k; i++) {
    b = upper_bound(v1.begin(), v1.end(), k - v2[i]) - v1.begin();
    if (b > 0)
      m = max(m, i + 1 + b);
    else
      m = max(m, i + 1);
  }
  cout << m << "\\n";

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

#include <iostream>
using namespace std;

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

  cin >> N >> M >> K;

  int A[N];
  int B[M];
  long long A_SUM[N + 1];
  long long B_SUM[M + 1];
  int k = 0;
  int ans = 0;

  A_SUM[0] = 0;
  B_SUM[0] = 0;

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

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

  for (int i = 1; i <= N; i++) {
    A_SUM[i] = A_SUM[i - 1] + A[i - 1];
  }

  for (int i = 1; i <= M; i++) {
    B_SUM[i] = B_SUM[i - 1] + B[i - 1];
  }

  int j = M;

  for (int i = 0; i <= N; i++) {
    if (A_SUM[i] > K) {
      break;
    }

    while (K < A_SUM[i] + B_SUM[j]) {
      j--;
    }

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  cin >> N >> M >> K;

  int A[N];
  int B[M];
  long long A_SUM[N + 1];
  long long B_SUM[M + 1];
  int k = 0;
  int ans = 0;

  A_SUM[0] = 0;
  B_SUM[0] = 0;

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

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

  for (int i = 1; i <= N; i++) {
    A_SUM[i] = A_SUM[i - 1] + A[i - 1];
  }

  for (int i = 1; i <= M; i++) {
    B_SUM[i] = B_SUM[i - 1] + B[i - 1];
  }

  for (int i = 0; i <= N; i++) {
    if (A_SUM[i] > K) {
      break;
    }

    for (int j = k; j <= M; j++) {
      if ((A_SUM[i] + B_SUM[M - j] <= K) && (i + (M - j) > ans)) {
        ans = i + (M - j);
        k = j;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

typedef long long ll;
typedef long double ld;

using namespace std;

ll n, m, k, arr1[N], arr2[N];

int main() {
  inlld3(n, m, k);
  for (ll a = 1; a <= n; a++) {
    inlld(arr1[a]);
    arr1[a] += arr1[a - 1];
  }
  for (ll a = 1; a <= m; a++) {
    inlld(arr2[a]);
    arr2[a] += arr2[a - 1];
  }
  ll ptr2 = m;
  ll ans = 0;
  while (arr2[ptr2] > k) {
    ptr2--;
  }
  ans = ptr2;
  for (ll ptr1 = 1; ptr1 <= n; ptr1++) {
    if (arr1[ptr1] > k)
      break;
    while (ptr2 > 0 && arr1[ptr1] + arr2[ptr2] > k) {
      ptr2--;
    }
    ans = max(ans, ptr1 + ptr2);
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

typedef long long ll;
typedef long double ld;

using namespace std;

ll n, m, k, arr1[N], arr2[N];

int main() {
  inlld3(n, m, k);
  for (ll a = 1; a <= n; a++) {
    inlld(arr1[a]);
    arr1[a] += arr1[a - 1];
  }
  for (ll a = 1; a <= m; a++) {
    inlld(arr2[a]);
    arr2[a] += arr2[a - 1];
  }
  ll ptr2 = m;
  ll ans = 0;
  while (arr2[ptr2] > k) {
    ptr2--;
  }
  ans = ptr2;
  for (ll ptr1 = 1; ptr1 <= n; ptr1++) {
    if (arr1[ptr1] > k)
      break;
    while (ptr2 > 0 && arr1[ptr1] + arr2[ptr2] > k) {
      ptr2--;
    }
    ans = max(ans, ptr1 + ptr2);
  }
  printf("%lld\\n", ans);
  return 0;
}