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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  vector<long long> b(m);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  vector<long long> A;
  vector<long long> B;
  A.push_back(0);
  B.push_back(0);
  for (int i = 0; i < n; i++) {
    A.push_back(A.at(i) + a.at(i));
  }
  for (int i = 0; i < m; i++) {
    B.push_back(B.at(i) + b.at(i));
  }

  int ans = 0, j = m;
  for (int i = 0; i <= n; i++) {
    if (A.at(i) > k) {
      break;
    }
    while (B.at(j) > k - A.at(i)) {
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  vector<long long> b(m);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  int nm = n + m;
  int acount = 0, bcount = 0;
  long long anstime = 0;
  int ans = 0;

  for (int i = 0; i < nm; i++) {
    if (acount < n && bcount < m) {
      if (a.at(acount) < b.at(bcount)) {
        anstime += a.at(acount);
        if (anstime > k)
          break;
        acount++;
        ans++;
      } else {
        anstime += b.at(bcount);
        if (anstime > k)
          break;
        bcount++;
        ans++;
      }
    } else {
      break;
    }
  }
  if (acount >= n) {
    while (bcount < m) {
      anstime += b.at(bcount);
      if (anstime > k)
        break;
      bcount++;
      ans++;
    }
  }
  if (bcount >= m) {
    while (acount < n) {
      anstime += a.at(bcount);
      if (anstime > k)
        break;
      acount++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

#define MAX_NM 200005
#define INF (1 << 30)

int N, M;
long long K;
long long A[MAX_NM], B[MAX_NM];

int main() {
  scanf("%d %d %lld", &N, &M, &K);
  for (int i = 0; i < MAX_NM; i++) {
    A[i] = B[i] = INF;
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld", A + i);
  }
  for (int i = 0; i < M; i++) {
    scanf("%lld", B + i);
  }

  long long AA[MAX_NM], BB[MAX_NM];
  AA[0] = 0, BB[0] = 0;
  for (int i = 1; i < MAX_NM; i++) {
    AA[i] = AA[i - 1] + A[i - 1];
  }
  for (int i = 1; i < MAX_NM; i++) {
    BB[i] = BB[i - 1] + B[i - 1];
  }
  // for (int i = 0; i < N; i++) {
  //   printf("%lld ", AA[i]);
  // }
  // puts("");
  // for (int i = 0; i < M; i++) {
  //   printf("%lld ", BB[i]);
  // }
  // puts("");

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

    int ok = 0, ng = M + 1;
    while (abs(ng - ok) > 1) {
      int mid = (ok + ng) / 2;
      if (AA[i] + BB[mid] <= K) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    if (AA[i] + BB[ok] <= K && ans < i + ok) {
      ans = i + ok;
    }
    // for (int j = 0; j <= M; j++) {
    //   if (AA[i] + BB[j] <= K && ans < i+j) {
    //     ans = i + j;
    //   }
    // }
  }
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

#define MAX_NM 200005
#define INF (1 << 30)

int N, M;
long long K;
long long A[MAX_NM], B[MAX_NM];

int main() {
  scanf("%d %d %lld", &N, &M, &K);
  for (int i = 0; i < MAX_NM; i++) {
    A[i] = B[i] = INF;
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld", A + i);
  }
  for (int i = 0; i < M; i++) {
    scanf("%lld", B + i);
  }

  long long AA[MAX_NM], BB[MAX_NM];
  AA[0] = 0, BB[0] = 0;
  for (int i = 1; i < MAX_NM; i++) {
    AA[i] = AA[i - 1] + A[i - 1];
  }
  for (int i = 1; i < MAX_NM; i++) {
    BB[i] = BB[i - 1] + B[i - 1];
  }
  // for (int i = 0; i < N; i++) {
  //   printf("%lld ", AA[i]);
  // }
  // puts("");
  // for (int i = 0; i < M; i++) {
  //   printf("%lld ", BB[i]);
  // }
  // puts("");

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

    int ok = 0, ng = M + 1;
    while (abs(ng - ok) > 1) {
      int mid = (ok + ng) / 2;
      if (AA[i] + BB[mid] <= K) {
        if (ans < i + mid) {
          ans = i + mid;
        }
        ok = mid;
      } else {
        ng = mid;
      }
    }
    for (int j = 0; j <= M; j++) {
      if (AA[i] + BB[j] <= K && ans < i + j) {
        ans = i + j;
      }
    }
  }
  printf("%d\\n", ans);
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

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

  ll ans = 0, j = M;
  rep(i, N + 1) {
    if (a[i] > K)
      break;
    while (b[j] > K - a[i])
      j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

vector<ll> A, B;

bool f(vector<ll> v, int i) { return i <= v.size() - 1; }

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  A.resize(N);
  B.resize(M);

  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];
  int ai = 0, bi = 0, ans = 0, t = 0;
  while (true) {
    if (!f(A, ai) && !f(B, bi))
      break;
    if (A[ai] > K && B[ai] > K)
      break;
    if (f(A, ai) && f(B, bi)) {
      if (A[ai] <= B[bi]) {
        K -= A[ai];
        ai++;
        ans++;
      } else if (B[bi] <= A[ai]) {
        K -= B[bi];
        bi++;
        ans++;
      }
    } else if (f(A, ai) && A[ai] <= K) {
      K -= A[ai];
      ai++;
      ans++;
    } else if (f(B, bi) && B[bi] <= K) {
      K -= B[bi];
      bi++;
      ans++;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(void) {

  int n, m, k;
  cin >> n >> m >> k;
  vi a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll t = 0;
  rep(i, m) t += b[i];
  int j = m;
  int ans = 0;
  rep(i, n + 1) {
    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 <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(void) {

  int n, m, k;
  cin >> n >> m >> k;
  vi A(n + 1, INF), B(n + 1, INF);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];
  ll cur_A = 0, cur_B = 0, sum = 0, cnt = 0;
  while (!(cur_A == n && cur_B == m)) {
    if (A[cur_A] < B[cur_B]) {
      sum += A[cur_A];
      cur_A++;
    } else {
      sum += B[cur_B];
      cur_B++;
    }
    if (k < sum)
      break;
    cnt++;
  }
  cout << cnt << endl;

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

#include <iostream>
using namespace std;
#define v long long
bool check = true;
v bins(v b[], v time, v n) {
  v l = 0, r = n, m;
  while (r > l + 1) {
    m = (l + r) / 2;
    // cout << m << ' ';
    if (b[m] < time) {
      l = m;
    } else if (b[m] > time) {
      r = m;
    } else {
      return m;
    }
    // cout << b[m] << ' ' << l << ' ' << r << endl;
  }
  m = (l + r) / 2;
  // cout << m << ' ' << b[m] << ' ' << time << endl;
  if (b[m] > time) {
    check = false;
    return 0;
  }
  return m;
}
int main() {
  v m, n, k;
  scanf("%lld %lld %lld", &m, &n, &k);
  v a[m], b[n];
  for (v i = 0; i < m; i++) {
    scanf("%lld", &a[i]);
    if (i > 0) {
      a[i] += a[i - 1];
    }
  }
  for (v i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    if (i > 0) {
      b[i] += b[i - 1];
    }
  }
  v max_books = 0;
  for (v x = 0; x <= m; x++) {
    v time_for_first;
    if (x == 0) {
      time_for_first = 0;
    } else if (a[x - 1] > k) {
      break;
    } else {
      time_for_first = a[x - 1];
      // cout << time_for_first << ' ';
    }
    v remaining_time = k - time_for_first;
    // cout << remaining_time << endl;
    v y = bins(b, remaining_time, n);
    if (check) {
      y++;
    } else {
      check = true;
    }
    // cout << x << ' ' << y << endl;
    if (x + y > max_books) {
      max_books = x + y;
    }
    // cout << endl;
  }
  printf("%lld\\n", max_books);
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
#define v long long int
v toread(queue<v> a, queue<v> b) {
  if (a.empty() != true && b.empty() != true) {
    return min(a.front(), b.front());
  } else if (a.empty()) {
    return a.front();
  } else {
    return b.front();
  }
}
int main() {
  v m, n, k, c = 0;
  queue<v> a, b;
  cin >> m >> n >> k;
  for (v i = 0; i < m; i++) {
    v tmp;
    cin >> tmp;
    a.push(tmp);
  }
  for (v i = 0; i < n; i++) {
    v tmp;
    cin >> tmp;
    b.push(tmp);
  }
  v tmp = 0;
  while (tmp + toread(a, b) <= k) {
    if (a.empty() != true && b.empty() != true) {
      if (a.front() <= b.front()) {
        tmp += a.front();
        a.pop();
      } else {
        tmp += b.front();
        b.pop();
      }
    } else if (a.empty()) {
      tmp += b.front();
      b.pop();
    } else {
      tmp += a.front();
      a.pop();
    }
    c++;
  }
  cout << c << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  /*#ifdef TarekHasan
      freopen("input.txt","r",stdin);
  #endif // TarekHasan*/

  int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> first(n);
  vector<long long int> second(m);

  for (int i = 0; i < n; i++)
    cin >> first[i];

  for (int i = 0; i < m; i++)
    cin >> second[i];

  for (int i = 1; i < n; i++)
    first[i] = first[i] + first[i - 1];
  for (int i = 1; i < m; i++)
    second[i] = second[i] + second[i - 1];

  /*for(long long int x : first)
      cout << x << " ";
  cout << endl;

  for(long long int x : second)
      cout << x << " ";
  cout << endl;*/

  int answer = 0;

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

    int t_a = i + 1;

    int t_k = k - first[i];

    int index = lower_bound(second.begin(), second.end(), t_k) - second.begin();

    if (index == m || second[index] > t_k)
      index -= 1;
    t_a += (index + 1);
    answer = max(answer, t_a);
  }

  for (int i = 0; i < m; i++) {
    if (second[i] > k)
      break;

    int t_a = i + 1;

    int t_k = k - second[i];

    int index = lower_bound(first.begin(), first.end(), t_k) - first.begin();

    if (index == n || first[index] > t_k)
      index -= 1;
    t_a += (index + 1);
    answer = max(answer, t_a);
  }

  cout << answer << endl;

#ifdef TarekHasan
  main();
#endif // TarekHasan

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  /*#ifdef TarekHasan
      freopen("input.txt","r",stdin);
  #endif // TarekHasan*/

  int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> first(n);
  vector<long long int> second(m);

  for (int i = 0; i < n; i++)
    cin >> first[i];

  for (int i = 0; i < m; i++)
    cin >> second[i];

  for (int i = 1; i < n; i++)
    first[i] = first[i] + first[i - 1];
  for (int i = 1; i < m; i++)
    second[i] = second[i] + second[i - 1];

  /*for(long long int x : first)
      cout << x << " ";
  cout << endl;

  for(long long int x : second)
      cout << x << " ";
  cout << endl;*/

  int answer = 0;

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

    int t_a = i + 1;

    int t_k = k - first[i];

    int index = lower_bound(second.begin(), second.end(), t_k) - second.begin();

    if (index == m || second[index] > t_k)
      index -= 1;
    t_a += (index + 1);
    answer = max(answer, t_a);
  }

  for (int i = 0; i < m; i++) {
    if (second[i] > k)
      break;

    int t_a = i + 1;

    int t_k = k - second[i];

    int index = lower_bound(first.begin(), first.end(), t_k) - first.begin();

    if (index == m || second[index] > t_k)
      index -= 1;
    t_a += (index + 1);
    answer = max(answer, t_a);
  }

  cout << answer << endl;

#ifdef TarekHasan
  main();
#endif // TarekHasan

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

#include <bits/stdc++.h>
#define rush()                                                                 \\
  int T;                                                                       \\
  scanf("%d", &T);                                                             \\
  int kase = 1;                                                                \\
  while (T--)
#define pb(x) push_back(x)
#define pr pair<int, int>
#define mem(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll maxn = 2e6 + 5;
const ll mod = 1e9 + 7;
ll quickpow(ll x, ll y, ll mod) {
  ll ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}

ll a[200005] = {0}, b[200005] = {0};

int main() {
  int A, B, k;
  cin >> A >> B >> k;
  int res = 0;
  for (int i = 1; i <= A; i++) {
    cin >> a[i];
    a[i] = a[i] + a[i - 1];
  }
  for (int i = 1; i <= B; i++) {
    cin >> b[i];
    b[i] = b[i] + b[i - 1];
  }
  for (int i = 0, j = B; i <= A; i++) {
    while (j && a[i] + b[j] > k)
      j--;
    if (a[i] + b[j] <= k)
      res = max(res, i + j);
  }
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int n, m, k, maxs = 0;
// xox,xoy,yox,yoy,lx,sumx,ly,sumy,
int a[2][200010];
int max(int a, int b) { return a > b ? a : b; }
void g(int x, int p1, int p2, int lx, int sumx) {
  if (sumx + a[x][p1] > k) {
    maxs = max(lx, maxs);
    // cout<<111<<endl;
    return;
  }
  if (sumx + a[x][p1] == k) {
    maxs = max(lx + 1, maxs);
    // cout<<111<<endl;
    return;
  }
  // cout<<111<<endl;
  lx++;
  sumx += a[x][p1];
  if (x == 0) {
    p1++;
    if (p1 < n)
      g(0, p1, p2, lx, sumx);
    else
      maxs = max(lx, maxs);
    if (p2 < m)
      g(1, p2, p1, lx, sumx);
    else
      maxs = max(lx, maxs);
  } else if (x == 1) {
    p1++;
    if (p2 < n)
      g(0, p2, p1, lx, sumx);
    else
      maxs = max(lx, maxs);
    if (p1 < m)
      g(1, p1, p2, lx, sumx);
    else
      maxs = max(lx, maxs);
  }
}

int main() {
  scanf("%d%d%d", &n, &m, &k);
  maxs = 0;
  for (int i = 0; i < n; i++)
    cin >> a[0][i];
  for (int i = 0; i < m; i++)
    cin >> a[1][i];
  if (a[0][0] > k && a[1][0] > k) {
    cout << 0 << endl;
    return 0;
  } // continue;}

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

#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
using namespace std;

bool isPrime(int n) {
  if (n < 2) {
    return 0;
  }
  if (n % 2 == 0) {
    return n == 2;
  }
  for (int i = 3; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  ll t = 0;
  ll no1 = 0;
  ll no2 = 0;
  for (int i = 1; i < n; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m; i++)
    b[i] += b[i - 1];
  for (int i = 0; i < n; i++) {
    ll curr = a[i];
    //  cout<<curr<<endl;
    if (curr > k)
      break;
    auto it = lower_bound(b.begin(), b.end(), k - curr + 1);
    int indx = it - b.begin();
    // cout<<"indx "<<indx<<" val "<<*it<<endl;
    if (indx <= 0)
      indx = 0;
    no1 = max((ll)(i + 1 + indx), no1);
  }
  for (int i = 0; i < m; i++) {
    ll curr = b[i];
    if (curr > k)
      break;
    auto it = lower_bound(a.begin(), a.end(), k - curr + 1);
    int indx = it - a.begin();
    if (indx <= 0)
      indx = 0;
    no2 = max((ll)(i + 1 + indx), no2);
  }

  cout << max(no1, no2) << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n1, n2, time, count = 0;
  cin >> n1 >> n2 >> time;
  long int arr1[n1], arr2[n2];
  for (int i = 0; i < n1; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < n2; i++) {
    cin >> arr2[i];
  }
  int j = 0, i = 0, flag = 1, c = 0;

  while (count < time || count == time) {

    if (arr1[j] < time && flag == 1 && j < n1) {
      count += arr1[j];
      if (count < time || count == time) {
        c++;
        flag = 2;
      } else {
        count -= arr1[j];
        flag = 2;
      }
    } else
      flag = 2;
    if (arr2[i] < time && flag == 2 && i < n2) {
      count += arr2[i];
      if (count < time || count == time) {
        c++;
        flag = 1;
      } else {
        count -= arr2[i];
        flag = 1;
      }
    }
    j++;
    i++;
    if (j >= n1 && i >= n2)
      break;
  }
  cout << c;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N, 0);
  vector<ll> B(M, 0);
  vector<ll> A_acc(N + 1, 0);
  vector<ll> B_acc(M + 1, 0);
  A_acc[0] = 0;
  B_acc[0] = 0;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A_acc[i + 1] = A_acc[i] + A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    B_acc[i + 1] = B_acc[i] + B[i];
  }

  cout << endl;
  // 決め打ち＋累積和＋２分探索
  ll ans = 0;
  for (int i = 0; i < N + 1; i++) {
    ll rem = K - A_acc[i];
    if (rem < 0)
      continue;
    ll cnt = upper_bound(B_acc.begin(), B_acc.end(), rem) - B_acc.begin();
    cnt--;
    ans = max(ans, cnt + i);
  }

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

Error: 0

Fixed submission:

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

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  queue<ll> A, B;
  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);
  }

  // 長さは最低1(0 indexed)
  ll cnt = 0;
  while (true) {
    // 両方空の場合
    if (A.empty() == true && B.empty() == true) {
      break;
    } else if (A.empty() && B.empty() == false) {
      // Aだけが空
      ll value = B.front();
      if (K >= value) {
        // 読み切れる
        K -= value;
        B.pop();
        cnt++;
      } else {
        // 読みきれない
        break;
      }
    } else if (A.empty() != false && B.empty()) {
      // Bだけが空
      ll value = A.front();
      if (K >= value) {
        // 読み切れる
        K -= value;
        A.pop();
        cnt++;
      }
    } else {
      // 両方残っている
      ll a_value, b_value;
      a_value = A.front();
      b_value = B.front();
      if (a_value < b_value) {
        // aの方がすぐ読める
        if (K >= a_value) {
          K -= a_value;
          A.pop();
          cnt++;
        } else {
          break;
        }
      } else {
        // bの方がすぐ読める
        if (K >= b_value) {
          K -= b_value;
          B.pop();
          cnt++;
        } else {
          break;
        }
      }
    }
  }

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

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

const char nl = '\\n';

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a{0}, b{0};
  int val;
  for (int i = 0; i < n; ++i) {
    cin >> val;
    a.push_back(a[i] + val);
  }
  for (int i = 0; i < m; ++i) {
    cin >> val;
    b.push_back(b[i] + val);
  }
  int ans = 0, j = m;
  for (int i = 0; i <= n; ++i) {
    if (a[i] > k)
      break;
    while (b[j] > k - a[i])
      --j;
    ans = max(ans, i + j);
  }
  cout << ans << nl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

const char nl = '\\n';

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a{0}, b{0};
  int val;
  for (int i = 0; i < n; ++i) {
    cin >> val;
    a.push_back(a[i] + val);
  }
  for (int i = 0; i < m; ++i) {
    cin >> val;
    b.push_back(b[i] + val);
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (a[i] > k)
      break;
    for (int j = m; j >= 0; --j) {
      if (b[j] <= k - a[i]) {
        ans = max(ans, i + j);
        break;
      }
    }
  }
  cout << ans << nl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, m, tim, a[200003], b[200003], ans;
int main() {
  cin >> n >> m >> tim;
  for (int i = 1; i <= n; i++)
    scanf("%lld", a + i), a[i] += a[i - 1];
  for (int i = 1; i <= m; i++)
    scanf("%lld", b + i), b[i] += b[i - 1];
  for (long long i = 0, j = m; i <= n; i++) {
    long long T = tim - a[i];
    if (T < 0)
      break;
    for (j; j >= 0 && b[j] > T; j--)
      ;
    ans = max(ans, i + j);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, m, tim, a[200003], b[200003];
int main() {
  cin >> n >> m >> tim;
  for (int i = 1; i <= n; i++)
    scanf("%lld", a + i), a[i] += a[i - 1];
  for (int i = 1; i <= m; i++)
    scanf("%lld", b + i), b[i] += b[i - 1];
  long long l, r, mid, ans = 0;
  for (int i = 0; i <= n; i++) {
    long long T = tim - a[i], res = i;
    if (T < 0)
      res = 0;
    l = 0, r = m;
    while (l != r) {
      mid = (l + r) / 2;
      if (b[mid] <= T)
        l = mid;
      else
        r = mid - 1;
      if (b[l + 1] <= T)
        l++;
      if (b[r] > T)
        r--;
    }
    ans = max(ans, res + l);
  }
  cout << ans;
}