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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  };
};
signed main() {
  cout << fixed << setprecision(20);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  REP2(i, n) {
    int aa;
    cin >> aa;
    a[i] = a[i - 1] + aa;
  }
  REP2(i, m) {
    int bb;
    cin >> bb;
    b[i] = b[i - 1] + bb;
  }
  int ia = 0, ib = 0;

  while (ia < n && a[ia + 1] <= k) {
    ia++;
  }

  while (ib < m && a[ia] + b[ib + 1] <= k) {
    ib++;
  }
  int ans = ia + ib;
  while (0 <= --ia) {
    while (ib < m && a[ia] + b[ib + 1] <= k) {
      ib++;
    }
    ans = max(ans, ia + ib);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  };
};
signed main() {
  cout << fixed << setprecision(20);
  int n, m, k, r = 0, ans = 0;
  cin >> n >> m >> k;
  vector<int> a(n), b(n);
  REP(i, n) {
    cin >> a[i];
    if (r += a[i] < k) {
      r += a[i];
      ans++;
    }
  }
  int aans = ans;
  int bans = 0;
  REP(i, n) cin >> b[i];
  if (ans == n) {
    while (r < k) {
      r += b[bans];
      bans++;
    }

  } else {
    while (r < k) {
      r -= a[aans];
      aans--;
      r += b[bans];
      bans++;
    }
  }
  cout << aans + bans;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <locale.h>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n, m, k;
  long long int a[200002], b[200002]; //
  int possa = 0;
  long long int ssx = 0, ax; //
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ssx += a[i];
    if (ssx <= k) {
      possa = i;
      ax = ssx;
    } // possaはAだけ読んだ時に読める本の数 その時にかかる時間がax
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
  }
  int nj = 1;
  long long int bx = 0; //
  int ans = possa;
  for (int i = possa; i >= 0; i--) {
    for (int j = nj; j <= m; j++) {
      if (ax + bx + b[nj] <= k) {
        bx += b[nj];
        nj++;
        ans = max(ans, (i + j));
      } else {
        break;
      }
    }
    ax -= a[i]; // axはiを読むまでにかかる時間を表す
  }
  printf("%d", ans);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <locale.h>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n, m, k;
  long long int a[200002], b[200002]; //
  int possa = 0;
  long long int ssx = 0, ax; //
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ssx += a[i];
    if (ssx <= k) {
      possa = i;
      ax = ssx;
    } // possaはAだけ読んだ時に読める本の数 その時にかかる時間がax
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
  }
  int nj = 1;
  long long int bx = 0; //
  int ans = possa;
  for (int i = possa; i >= 0; i--) {
    for (int j = nj; j <= m; j++) {
      if (ax + bx + b[nj] <= k) {
        bx += b[nj];
        nj++;
        ans = max(ans, (i + j));
      }
    }
    ax -= a[i]; // axはiを読むまでにかかる時間を表す
  }
  printf("%d", ans);
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265358979323846264338327950L

vector<long long> A, B;
long long K;

int main(void) {

  long long N, M, tmp, ans = 0, time = 0, total = 0, b_max;

  cin >> N >> M >> K;

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

  A_sum.push_back(0);
  for (long long i = 1; i <= N; i++) {
    cin >> tmp;
    A.push_back(tmp);
    A_sum[i] = A_sum[i - 1] + tmp;
  }

  B_sum.push_back(0);
  for (long long i = 1; i <= M; i++) {
    cin >> tmp;
    B.push_back(tmp);
    B_sum[i] = B_sum[i - 1] + tmp;
  }

  ans = 0;
  long long tmp_m = M;
  for (long long i = 0; i <= N; i++) {
    for (long long j = tmp_m; j >= 0; j--) {
      if (A_sum[i] + B_sum[j] <= K) {
        if (ans < i + j) {
          ans = i + j;
        }
        tmp_m = j;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265358979323846264338327950L

vector<long long> dp;
vector<long long> A, B, A_sum, b_sum;
long long K;

int main(void) {

  long long N, M, tmp, ans = 0, time = 0, total = 0, b_max;

  cin >> N >> M >> K;

  total = 0;
  A_sum.push_back(total);
  for (long long i = 0; i < N; i++) {
    cin >> tmp;
    A.push_back(tmp);
    total += tmp;
    A_sum.push_back(total);
  }

  total = 0;
  b_sum.push_back(total);
  for (long long i = 0; i < M; i++) {
    cin >> tmp;
    B.push_back(tmp);
    total += tmp;
    b_sum.push_back(total);
  }

  for (long long i = M; i >= 0; i--) {
    if (b_sum[i] <= K) {
      b_max = i;
      break;
    }
  }

  ans = 0;
  for (long long i = 0; i <= N; i++) {
    if (A_sum[i] > K)
      break;
    for (long long j = b_max; j >= 0; j--) {
      if (A_sum[i] + b_sum[j] <= K) {
        if (ans < i + j) {
          ans = i + j;
          break;
        }
      }
    }
  }

  cout << ans << endl;

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

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

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  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 b_cnt = m;
  int res = 0;
  rep(a_cnt, n + 1) {
    if (a[a_cnt] > k)
      break;
    while (a[a_cnt] + b[b_cnt] > k)
      --b_cnt;
    res = max(res, a_cnt + b_cnt);
  }

  cout << res << endl;

  return 0;
}

Error: -11

Fixed submission:

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

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  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 b_cnt = m;
  int res = 0;
  rep(a_cnt, n + 1) {
    while (a[a_cnt] + b[b_cnt] > k)
      --b_cnt;
    res = max(res, a_cnt + b_cnt);
  }

  cout << res << endl;

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

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

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

Error: 0

Fixed submission:

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

int main() {
  queue<int> a;
  queue<int> b;
  ll n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    ll A;
    cin >> A;
    a.push(A);
  }
  for (int i = 0; i < m; i++) {
    ll B;
    cin >> B;
    b.push(B);
  }
  int minute = 0, ans = 0;
  while (minute <= k) {
    if (a.front() < b.front()) {
      minute += a.front();
      a.pop();
      ans++;
    } else {
      minute += b.front();
      b.pop();
      ans++;
    }
    if (minute > k)
      break;
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll a[200010], b[200010];

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

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

  ans = 0;
  ll j = m;
  for (int i = 0; i <= n; ++i) {
    if (a[i] > k)
      break;

    while (a[i] + b[j] > k) {
      --j;
    }
    ans = max(ans, i + j);
  }

  std::cout << ans << endl;

  return (0);
}


Error: TLE

Fixed submission:

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

ll a[200010], b[200010];

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

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

  ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (a[i] > k)
      break;

    ll j = m;
    while (a[i] + b[j] > k) {
      --j;
    }
    ans = max(ans, i + j);
  }

  std::cout << ans << endl;

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

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

int const N = 2e5 + 7;

int n, m, k;
long long A[N] = {}, B[N] = {};

int binser(int num) {
  int lt = 1, rt = m + 1;
  while (lt < rt) {
    int mid = (lt + rt) / 2;
    if (B[mid] <= num)
      lt = mid + 1;
    else
      rt = mid;
  }
  return lt - 1;
}

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

  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 res = 0;
  for (int i = 0; i <= n; ++i) {
    if (A[i] > k)
      break;
    res = max(res, i + binser(k - A[i]));
  }
  cout << res << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int const N = 2e5 + 7;

int n, m, k;
long long A[N] = {}, B[N] = {};

int binser(int num) {
  if (B[1] > num)
    return 0;
  if (B[m] <= num)
    return m;

  int lt = 1, rt = m;
  while (lt < rt) {
    int mid = (lt + rt) / 2;
    if (B[mid] < num)
      lt = mid;
    else
      rt = mid - 1;
  }
  return lt;
}

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

  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 res = 0;
  for (int i = 0; i <= n; ++i) {
    if (A[i] > k)
      break;
    res = max(res, i + binser(k - A[i]));
  }
  cout << res << '\\n';
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
const ll modP = 1000000007;

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> cumSumA(n + 1);
  cumSumA[0] = 0;
  for (int i = 0; i < n; i++) {
    cumSumA[i + 1] = cumSumA[i] + A[i];
  }
  vector<ll> cumSumB(m + 1);
  cumSumB[0] = 0;
  for (int i = 0; i < m; i++) {
    cumSumB[i + 1] = cumSumB[i] + B[i];
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (cumSumA[i] > k)
      break;
    ll key = k - cumSumA[i];
    auto iter = lower_bound(cumSumB.begin(), cumSumB.end(), key);
    int j = iter - cumSumB.begin();
    if (j > m)
      j = m;
    if (cumSumB[j] > key) {
      j--;
    }
    ans = max(ans, i + j);
    // cout<<cumSumA[i] + cumSumB[j]<<endl;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
const ll modP = 1000000007;

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> cumSumA(n + 1);
  cumSumA[0] = 0;
  for (int i = 0; i < n; i++) {
    cumSumA[i + 1] = cumSumA[i] + A[i];
  }
  vector<ll> cumSumB(m + 1);
  cumSumB[0] = 0;
  for (int i = 0; i < m; i++) {
    cumSumB[i + 1] = cumSumB[i] + B[i];
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (cumSumA[i] > k)
      break;
    for (ll j = 0; j <= m; j++) {
      if (cumSumA[i] + cumSumB[j] <= k) {
        ans = max(ans, i + j);
      } 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 int ll;

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


Error: 0

Fixed submission:

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

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

  vector<ll> c(n + 1, 0);
  vector<ll> d(m + 1, 0);
  c[0] = 0;
  d[0] = 0;
  for (ll i = 1; i < n + 1; i++) {
    c[i] += c[i - 1] + a[i];
  }
  for (ll i = 1; i < m + 1; i++) {
    d[i] += d[i - 1] + b[i];
  }
  ll res = 0;
  ll r = m;
  for (ll i = 0; i < n + 1; i++) {
    // if (c[i] > k) break;
    while (d[r] > k - c[i]) {
      r--;
    }
    res = max(res, i + r);
  }
  cout << res << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 1000000001

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

  int *A, *B;

  A = (int *)malloc(sizeof(int) * n + 1);
  B = (int *)malloc(sizeof(int) * m + 1);

  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &B[i]);
  }

  long long int *a, *b;

  a = (long long int *)malloc(sizeof(long long int) * n + 2);
  b = (long long int *)malloc(sizeof(long long int) * m + 2);

  a[0] = 0;
  b[0] = 0;

  int t, s;

  for (int i = 1; i <= n; i++) {
    t = i;
    a[i] = A[i - 1] + a[i - 1];
    if (a[i] > k) {
      t = i - 1;
      break;
    }
  }

  for (int i = 1; i <= m; i++) {
    s = i;
    b[i] = B[i - 1] + b[i - 1];
    if (b[i] > k) {
      s = i - 1;
      break;
    }
  }

  int ans = 0;

  for (int i = 0; i <= t; i++) {
    int j = s;
    while (a[i] + b[j] > k) {
      j--;
      if (j == 0)
        break;
    }
    s = j;
    ans = max(ans, j + i);
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define MAX 1000000001

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

  int *A, *B;

  A = (int *)malloc(sizeof(int) * n + 1);
  B = (int *)malloc(sizeof(int) * m + 1);

  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &B[i]);
  }

  long long int *a, *b;

  a = (long long int *)malloc(sizeof(long long int) * n + 1);
  b = (long long int *)malloc(sizeof(long long int) * m + 1);

  a[0] = 0;
  b[0] = 0;

  int t, s;

  for (int i = 1; i <= n; i++) {
    t = i;
    a[i] = A[i - 1] + a[i - 1];
    if (a[i] > k) {
      break;
    }
  }

  for (int i = 1; i <= m; i++) {
    s = i;
    b[i] = B[i - 1] + b[i - 1];
    if (b[i] > k) {
      break;
    }
  }

  int ans = 0;

  for (int i = 0; i <= t; i++) {
    int j = s;
    while (a[i] + b[j] > k) {
      j--;
      if (j == 0)
        break;
    }
    s = j;
    ans = max(ans, j + i);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m, k, p = 0, s, ans = 0;
  cin >> n >> m >> k;
  int64_t a[n + 1], b[m + 1];
  a[0] = 0, b[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    int aa;
    cin >> aa;
    a[i] = a[i - 1] + aa;
  }
  for (int i = 1; i < m + 1; i++) {
    int bb;
    cin >> bb;
    b[i] = b[i - 1] + bb;
  }
  int t = m;
  while (p <= n && a[p] <= k) {
    for (int i = t; i >= 0; i--) {
      if (b[i] + a[p] <= k) {
        s = i;
        break;
      }
    }
    t = s;
    ans = max(ans, p + s);
    p++;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m, k, p = 0, s, ans = 0;
  cin >> n >> m >> k;
  int64_t a[n + 1], b[m + 1];
  a[0] = 0, b[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    int aa;
    cin >> aa;
    a[i] = a[i - 1] + aa;
  }
  for (int i = 1; i < m + 1; i++) {
    int bb;
    cin >> bb;
    b[i] = b[i - 1] + bb;
  }
  int t = m + 1;
  while (p <= n) {
    s = 0;
    if (a[p] > k)
      break;
    for (int i = 0; i < t; i++) {
      if (b[i] + a[p] <= k)
        s++;
    }
    t = s;
    ans = max(ans, p + s - 1);
    p++;
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  //
  long long n, m, k;
  long long time = 0;

  cin >> n >> m >> k;

  vector<long long> A(n);
  vector<long long> B(m);

  for (long long i = 0; i < n; i++)
    cin >> A.at(i);
  for (long long i = 0; i < m; i++) {
    cin >> B.at(i);
    time += B.at(i);
  }

  long long j = m;
  long long kekka = 0;

  for (long long i = 0; i < n + 1; i++) {
    while (j > 0 && time > k) {
      j--;
      time -= B.at(j);
    }

    if (time > k)
      break;
    kekka = max(kekka, i + j);

    if (i == n)
      break;
    time += A.at(i);
  }

  cout << kekka;
  //
}


Error: WA

Fixed submission:

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

int main() {
  //
  long long n, m, k;
  long long tot = 0;

  cin >> n >> m >> k;

  vector<long long> A(n);
  vector<long long> B(m);

  for (long long i = 0; i < n; i++)
    cin >> A.at(i);
  for (long long i = 0; i < m; i++) {
    cin >> B.at(i);
    tot += B.at(i);
  }

  long long j = m;
  long long kekka = 0;

  for (int i = 0; i < n + 1; i++) {
    while (j > 0 && tot > k) {
      j -= 1;
      tot -= B.at(i);
    }

    if (tot > k)
      break;
    kekka = max(kekka, i + j);

    if (i == n)
      break;
    tot += A.at(i);
  }

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

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

int main() {
  int n, m, ky, kx, d = 0, w = 1;
  cin >> n >> m >> ky;
  long long a[n + 1];
  long long b[m + 1];
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = a[i] + a[i - 1];
    if (a[i] <= ky)
      d = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] = b[i] + b[i - 1];
  }
  for (int i = d; i >= 0; i--) {
    kx = ky - a[i];
    for (int p = w; p <= m; p++) {
      if (b[p] > kx)
        break;
      else if (d < i + p)
        d = i + p;
      w = p;
    }
  }
  cout << d;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, ky, kx, d = 0;
  cin >> n >> m >> ky;
  long long a[n + 1];
  long long b[m + 1];
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = a[i] + a[i - 1];
    if (a[i] <= ky)
      d = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] = b[i] + b[i - 1];
  }
  for (int i = d; i >= 0; i--) {
    kx = ky - a[i];
    for (int p = 1; p <= m; p++) {
      if (b[p] > kx)
        break;
      else if (d < i + p)
        d = i + p;
    }
  }
  cout << d;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

long long A[200002], B[200002], N, M, K;

int main() {
  long long i, j;
  cin >> N >> M >> K;
  rep0(i, N) {
    cin >> j;
    A[i + 1] = A[i] + j;
  }
  rep0(i, M) {
    cin >> j;
    B[i + 1] = B[i] + j;
  }

  long long ans = 0, t = 0;
  j = M;

  rep0(i, N + 1) {
    if (A[i] > K)
      break;
    while (A[i] + B[j] > K) {
      --j;
    }
    ans = max(ans, j + i);
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

long long A[200002], B[200002], N, M, K;

int main() {
  long long i, j, k;
  cin >> N >> M >> K;
  rep0(i, N) {
    cin >> j;
    A[i + 1] = A[i] + j;
  }
  rep0(i, M) {
    cin >> j;
    B[i + 1] = B[i] + j;
  }

  long long ans = 0, t = 0;
  i = j = 0;

  rep0(i, N + 1) {
    if (A[i] > K)
      break;
    rep0(j, M + 1) {
      if (A[i] + B[j] <= K)
        ans = max(ans, i + j);
      else
        break;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

long long int psumA[200001];
long long int psumB[200001];
int A[200001], B[200001];

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

  int n, m, k;

  cin >> n >> m >> k;

  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> B[i];
  }

  for (int i = 1; i <= n; i++) {
    psumA[i] = psumA[i - 1] + A[i];
  }
  for (int i = 1; i <= m; i++) {
    psumB[i] = psumB[i - 1] + B[i];
  }

  int res = 0;

  for (int i = 0; i <= n; i++) {
    if (psumA[i] > k) {
      break;
    }
    int lo = 0;
    int hi = m;
    int Max = 0;
    long long int val = k - psumA[i];
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (psumB[mid] <= val) {
        Max = max(Max, mid);
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    res = max(res, i + Max);
  }

  cout << res << '\\n';

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long int psumA[100001];
long long int psumB[100001];
int A[100001], B[100001];

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

  int n, m, k;

  cin >> n >> m >> k;

  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> B[i];
  }

  for (int i = 1; i <= n; i++) {
    psumA[i] = psumA[i - 1] + A[i];
  }
  for (int i = 1; i <= m; i++) {
    psumB[i] = psumB[i - 1] + B[i];
  }

  int res = 0;

  for (int i = 0; i <= n; i++) {
    if (psumA[i] > k) {
      break;
    }
    int lo = 0;
    int hi = m;
    int Max = 0;
    long long int val = k - psumA[i];
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (psumB[mid] <= val) {
        Max = max(Max, mid);
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    res = max(res, i + Max);
  }

  cout << res << '\\n';

  return 0;
}