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

#include <stdio.h>

int main() {
  char s[200010], t[200010];

  scanf("%s", s);
  scanf("%s", t);

  int i = 0;
  int diff = 0;

  while (s[i] != '\\0') {
    if (s[i] != t[i]) {
      diff++;
    }

    i++;
  }

  printf("%d", diff);
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  char s[20010], t[20010];

  scanf("%s", s);
  scanf("%s", t);

  int i = 0;
  int diff = 0;

  while (s[i] != '\\0') {
    if (s[i] != t[i]) {
      diff++;
    }

    i++;
  }

  printf("%d", diff);
}
Problem p02622 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  char s[200010], t[200010];
  int c = 0;
  scanf("%s %s", s, t);
  for (int i = 0; i < strlen(s); i++) {
    // printf("%c ",s[i]);
    if (s[i] == t[i]) {
      c++;
    }
  }
  printf("%ld\\n", (strlen(s) - c));
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  char s[20010], t[20010];
  int c = 0;
  scanf("%s %s", s, t);
  for (int i = 0; i < strlen(s); i++) {
    // printf("%c ",s[i]);
    if (s[i] == t[i]) {
      c++;
    }
  }
  printf("%ld\\n", (strlen(s) - c));
}
Problem p02622 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  char S[200001], T[200001];
  int ans = 0;

  scanf("%s", S);
  scanf("%s", T);

  for (int i = 0; S[i] != '\\0'; i++) {
    if (S[i] != T[i])
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  char S[200000], T[200000];
  int ans = 0;

  scanf("%s", S);
  scanf("%s", T);

  for (int i = 0; S[i] != '\\0'; i++) {
    if (S[i] != T[i])
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02622 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int64_t sum = 0;
  for (int i = 0; i < s1.size(); i++)
    sum += (s1[i] != s2[i]);
  cout << sum << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string A, B;
  int m, n, count = 0;
  n = A.length();
  m = B.length();
  while (n == m) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (A[i] == B[j])
          continue;
        else if (A[i] != B[j])
          count++;
        i++;
        j++;
      }
    }
  }
  cout << count;
  return 0;
}
Problem p02622 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define NUM 200001
int main() {
  int i, cnt = 0, errno;
  char s[NUM], t[NUM];
  errno = scanf("%s", s);
  errno = scanf("%s", t);

  if (errno) {
    ;
  }

  for (i = 0; s[i] != '\\0'; i++) {
    if (s[i] != t[i]) {
      cnt++;
    }
  }
  printf("%d", cnt);
}

Error: WA

Fixed submission:

#include <stdio.h>
#define NUM 20001
int main() {
  int i, cnt = 0, errno;
  char s[NUM], t[NUM];
  errno = scanf("%s", s);
  errno = scanf("%s", t);

  if (errno) {
    ;
  }

  for (i = 0; s[i] != '\\0'; i++) {
    if (s[i] != t[i]) {
      cnt++;
    }
  }
  printf("%d", cnt);
}
Problem p02622 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n = 0;
  string arr, arr1;
  cin >> arr >> arr1;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] != arr1[i])
      n++;
  }
  cout << n;
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  long limit = 2 * (10 ^ 5);
  char str1[limit];
  cin >> str1;
  char str2[limit];
  cin >> str2;
  int answer = 0;
  int size_ = strlen(str1);
  for (int i = 0; i < size_; i++) {
    if (str1[i] != str2[i]) {
      answer++;
    }
  }
  cout << answer << endl;
  return 0;
}
Problem p02622 (C++) — buggy submission, verdict: Runtime Error

// Tue May 26 19:06:02 IST 2020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define forn(ii, a, b) for (int ii = (int)a; ii < (int)b; ii++)
#define debug(x) cerr << #x << " " << x << " -- \\n"
#define I__O ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int64 long long
#define MOD 998244353
#define pb push_back
#define f1 first
#define s1 second
#define all(x) (x).begin(), (x).end()
#define precise(x) cout << fixed << setprecision(12) << x << '\\n';
#define tough_nut numeric_limits<int64>::min()

const double pi = 3.141592653589793238;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int N = 3e5 + 7;
const int INF = INT_MAX;
struct comp {
  bool operator()(const pair<int, int> A, const pair<int, int> &B) const {
    if (A.first == B.first)
      return A.second < B.second;
    return A.first > B.first;
  }
};
int tests() {
  string S, T;
  cin >> S >> T;
  int c = 0;
  int n = S.size();
  for (int i = 0; i < n; i++)
    c += (S[i] != T[i]);
  cout << c << '\\n';
  return 0;
  // cout << (n+1-min(a,b)+max(a,b)-1)/max(a,b) << '\\n';
}
int32_t main() {
  I__O;
  int cases = 1;
  // cin >> cases ;
  while (cases--)
    tests();

  return 0;
}
// g++ -std=c++17 -O2 -Wall test.cpp

Error: 0

Fixed submission:

// Tue May 26 19:06:02 IST 2020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define forn(ii, a, b) for (int ii = (int)a; ii < (int)b; ii++)
#define debug(x) cerr << #x << " " << x << " -- \\n"
#define I__O ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int64 long long
#define MOD 998244353
#define pb push_back
#define f1 first
#define s1 second
#define all(x) (x).begin(), (x).end()
#define precise(x) cout << fixed << setprecision(12) << x << '\\n';
#define tough_nut numeric_limits<int64>::min()

const double pi = 3.141592653589793238;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int N = 3e5 + 7;
const int INF = INT_MAX;
struct comp {
  bool operator()(const pair<int, int> A, const pair<int, int> &B) const {
    if (A.first == B.first)
      return A.second < B.second;
    return A.first > B.first;
  }
};
int tests() {
  string S, T;
  cin >> S >> T;
  int c = 0;
  int n = S.size();
  for (int i = 0; i < n; i++)
    c += (S[i] != T[i]);
  cout << c << '\\n';
  // cout << (n+1-min(a,b)+max(a,b)-1)/max(a,b) << '\\n';
}
int32_t main() {
  I__O;
  int cases = 1;
  // cin >> cases ;
  while (cases--)
    tests();

  return 0;
}
// g++ -std=c++17 -O2 -Wall test.cpp
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll A[n];
  ll a[n + 1];
  a[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    a[i + 1] = a[i] + A[i];
  }

  ll B[m];
  ll b[m + 1];
  b[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> B[i];
    b[i + 1] = b[i] + B[i];
  }

  ll ans = 0;
  ll 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;

  return 0;
}

Error: TLE

Fixed submission:

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

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

  long long a[n];
  long long b[m];

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

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

  int ans = 0;
  while (true) {
    int i = 0;
    int j = 0;
    long long sum = 0;
    if (sum + min(a[i], b[i]) > k)
      break;

    sum += min(a[i], b[j]);
    if (a[i] < b[j]) {
      i++;
      ans++;
    } else if (a[i] > b[j]) {
      j++;
      ans++;
    } else {
      if (a[i + 1] < b[j + 1]) {
        i++;
        ans++;
      }
      if (a[i] > b[j]) {
        j++;
        ans++;
      }
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll fun(vector<ll> &a, vector<ll> &b, ll k) {
  ll ans = 0;
  ll finans = 0;
  auto it = upper_bound(a.begin(), a.end(), k);
  if (it == a.begin()) {
    auto it1 = upper_bound(b.begin(), b.end(), k);
    if (it1 == b.begin()) {
      ans = 0;
    } else {
      it1--;
      ans += it1 - b.begin() + 1;
      finans = max(ans, finans);
    }
  } else {
    it--;
    ans = 0;
    for (ll i = 0; i <= it - a.begin(); i++) {
      ans = 0;
      auto it1 = upper_bound(b.begin(), b.end(), k - a[i]);
      if (it1 == b.begin()) {
        ans += i + 1;
      } else {
        it1--;
        ans += i + 1 + it1 - b.begin() + 1;
      }
      finans = max(ans, finans);
    }
  }
  return finans;
}
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (ll i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  for (ll i = 1; i < m; i++) {
    b[i] += b[i - 1];
  }
  cout << max(fun(a, b, k), fun(b, a, k)) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (ll i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  for (ll i = 1; i < m; i++) {
    b[i] += b[i - 1];
  }
  ll ans = 0;
  ll finans = 0;
  auto it = upper_bound(a.begin(), a.end(), k);
  while (it != a.begin()) {
    ans = 0;
    it--;
    ans += it - a.begin() + 1;
    k -= *it;
    auto it1 = upper_bound(b.begin(), b.end(), k);
    if (it1 != b.begin()) {
      it1--;
      ans += it1 - b.begin() + 1;
      k -= *it1;
    }
    finans = max(finans, ans);
  }
  auto it1 = upper_bound(b.begin(), b.end(), k);
  while (it1 != b.begin()) {
    ans = 0;
    it--;
    ans += it1 - b.begin() + 1;
    k -= *it;
    auto it = upper_bound(a.begin(), a.end(), k);
    if (it != a.begin()) {
      it--;
      ans += it - a.begin() + 1;
      k -= *it;
    }
    finans = max(finans, ans);
  }
  cout << finans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, m, k, v;
  cin >> n >> m >> k;
  vector<ll> s1, s2;
  s1.push_back(0), s2.push_back(0);
  for (int i = 0; i < n; i++) {
    cin >> v;
    s1.push_back(s1.back() + v);
  }
  for (int i = 0; i < m; i++) {
    cin >> v;
    s2.push_back(s2.back() + v);
  }
  ll best = 0;
  // i amount on s1
  int j = m; // j on s2
  int res = 0;
  for (int i = 0; i <= n; i++) {
    while (j > 0 && s2[j] + s1[i] > k) {
      j--;
    }
    if (s2[j] + s1[i] <= k) {
      res = max(res, i + j);
    }
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

// Author : Vipul Sharma

// LIBRARIES
#include <bits/stdc++.h>

// MACROS
#define ll long long int
#define ld long double
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rev(i, b, a) for (ll i = b - 1; i >= a; i--)
#define eqrep(i, a, b) for (ll i = 1; i <= b; i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define w(t) while (t--)
#define booster                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define mod 1000000007
#define endl "\\n"
#define INF 0x3f3f3f3f
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\\t" << #y << " : " << y << endl;
#define deb3(x, y, z)                                                          \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << endl;
#define deb4(x, y, z, w)                                                       \\
  cout << #x << " : " << x << "\\t" << #y << " : " << y << "\\t" << #z << " : "  \\
       << z << "\\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e)                                                    \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f)                                                 \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \\
       << #f << ": " << f << endl;

using namespace std;
long long cost = 1e18;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  booster;
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n], b[m];
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, m) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  ll i = 0, sum = 0;
  ll cnt = 0;
  while (sum <= k) {
    if (sum + a[i] <= k) {
      sum += a[i];
      i++;
      cnt++;
    }
  }
  i = 0;
  while (sum <= k) {
    if (sum + b[i] <= k) {
      sum += b[i];
      i++;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }

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

  ll tmp_ans = 0;
  ll cost = 0;
  vecll a(n), b(m);
  vector<ll> anss;

  ll a_itr = 0;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    if (cost + a[i] <= k) {
      tmp_ans++;
      cost += a[i];
      a_itr = i + 1;
    } else {
      break;
    }
  }
  ll b_itr = 0;
  rep(i, m) { cin >> b[i]; }

  anss.push_back(tmp_ans);
  while (b_itr < m) {
    if (cost + b[b_itr] <= k) {
      tmp_ans++;
      anss.push_back(tmp_ans);
      cost += b[b_itr++];
    } else {
      if (a_itr == 0)
        break;
      anss.push_back(tmp_ans);
      cost -= a[--a_itr];
      tmp_ans--;
    }
  }
  cout << *max_element(all(anss)) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }

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

  ll tmp_ans = 0;
  ll cost = 0;
  vecll a(n), b(m);
  vector<ll> anss;

  bool is_end = false;
  ll a_itr = -1;
  rep(i, n) {
    cin >> a[i];
    if (is_end == false) {
      if (cost + a[i] <= k) {
        tmp_ans++;
        cost += a[i];
        a_itr = i + 1;
      } else {
        is_end = true;
      }
    }
  }
  is_end = false;
  ll b_itr = -1;
  rep(i, m) {
    cin >> b[i];
    if (is_end == false) {
      if (cost + b[i] <= k) {
        tmp_ans++;
        cost += b[i];
        b_itr = i + 1;
      } else {
        is_end = true;
      }
    }
  }

  anss.push_back(tmp_ans);
  while (b_itr < m) {
    if (cost + b[b_itr] <= k) {
      tmp_ans++;
      anss.push_back(tmp_ans);
      cost += b[b_itr++];
    } else {
      if (a_itr == 0)
        break;
      anss.push_back(tmp_ans);
      cost -= a[--a_itr];
      tmp_ans--;
    }
  }
  cout << *max_element(all(anss)) << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];
  ll c = 0;
  ll s = 0;
  rep(i, n) {
    if (s + a[i] <= k) {
      s += a[i];
      c++;
    } else {
      break;
    }
  }
  ll d = 0;
  rep(i, m) {
    if (s + b[i] <= k) {
      s += b[i];
      d++;
    } else {
      break;
    }
  }
  ll ans = c + d;
  // cout<<c<<"  "<<d<<endl;
  ll c_ = c;
  rep(i, c_) {
    s -= a[c - 1];
    c--;
    // cout<<c<<"  ";
    if (d < m) {
      while (s + b[d] <= k) {
        s += b[d];
        d++;
        if (d == m) {
          break;
        }
      }
    } // cout<<d<<endl;
    ans = max(ans, c + d);
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];
  ll c = 0;
  ll s = 0;
  rep(i, n) {
    if (s + a[i] <= k) {
      s += a[i];
      c++;
    } else {
      break;
    }
  }
  ll d = 0;
  rep(i, m) {
    if (s + b[i] <= k) {
      s += b[i];
      d++;
    } else {
      break;
    }
  }
  ll ans = c + d;
  /*rep(i,c){
    x=i;
    ll j=0,k_=k;
    while(k_>=b[j]&&j<m){k_-=b[j]; j++; x++;}
    k-=a[i];//cout<<k;
    ans=max(x,ans);
  }*/
  rep(i, c) {
    s -= a[c - 1];
    c--;
    while (s + b[d] <= k) {
      s += b[d];
      d++;
      if (d == m - 1) {
        break;
      }
    }
    ans = max(ans, c + d);
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(I, N) for (int I = 0; I < N; I++)
using ll = long long int;
using namespace std;
int ans = 0;
const int N = 200000;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[1000000], b[1000000];
  a[0] = 0;
  b[0] = 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 j = m;
  for (int i = 0; i <= n; i++) {

    if (k < a[i])
      break;

    for (; k < (a[i] + b[j]); j--)
      ;

    ans = max(ans, i + j);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define rep(I, N) for (int I = 0; I < N; I++)
using ll = long long int;
using namespace std;
int ans = 0;
const int N = 200000;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[1000000], b[1000000];
  a[0] = 0;
  b[0] = 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];
  }
  for (int i = 0; i <= n; i++) {

    if (k < a[i])
      break;
    int j = m;
    for (; k < (a[i] + b[j]); j--)
      ;

    ans = max(ans, i + j);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  rep2(i, 1, n + 1) {
    cin >> a[i];
    if (i != 0)
      a[i] += a[i - 1];
  }

  int lim_b = m;
  rep2(i, 1, m + 1) {
    cin >> b[i];
    if (i != 0)
      b[i] += b[i - 1];
    if (b[i] > k)
      lim_b = (i < lim_b) ? i : lim_b;
  }

  ll ans = 0;
  rep(i, n + 1) {
    if (a[i] > k)
      break;
    for (int j = lim_b; j >= 0; j--) {
      if (a[i] + b[j] <= k) {
        ans = (i + j) > ans ? (i + j) : ans;
        lim_b = j;
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

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

  rep2(i, 1, n + 1) {
    cin >> a[i];
    if (i != 0)
      a[i] += a[i - 1];
  }
  rep2(i, 1, m + 1) {
    cin >> b[i];
    if (i != 0)
      b[i] += b[i - 1];
  }

  ll ans = 0;
  rep(i, n + 1) {
    if (a[i] > k)
      break;
    rep(j, m + 1) {
      if (a[i] + b[j] <= k) {
        ans = (i + j) > ans ? (i + j) : ans;
      } else {
        break;
      }
    }
  }

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

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

inline int D() {
  int t;
  scanf("%d", &t);
  return t;
}
inline ll LLD() {
  ll t;
  scanf("%lld", &t);
  return t;
}
// const int INF = 0x3f3f3f3f;
// const int mod=1e9+7;
// const double pi=3.14159265359;
// ###################################################################

int main() {
  int n = D(), m = D(), k = D();
  int a[n], b[m];
  ll cm1[n + 1], cm2[m + 1];
  cm1[0] = 0, cm2[0] = 0;
  for (int i = 0; i <= n; i++) {
    if (i < n)
      a[i] = D();
    if (i)
      cm1[i] = cm1[i - 1] + a[i - 1];
  }

  for (int i = 0; i <= m; i++) {
    if (i < m)
      b[i] = D();
    if (i)
      cm2[i] = cm2[i - 1] + b[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n && cm1[i] <= k; i++) {
    if (cm1[i] > k)
      break;
    int it = upper_bound(cm2, cm2 + m + 1, (k - cm1[i])) - cm2;
    ans = max(ans, i + it - 1);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

inline int D() {
  int t;
  scanf("%d", &t);
  return t;
}
inline ll LLD() {
  ll t;
  scanf("%lld", &t);
  return t;
}
// const int INF = 0x3f3f3f3f;
// const int mod=1e9+7;
// const double pi=3.14159265359;
// ###################################################################

int main() {
  int n = D(), m = D(), k = D();
  int a[n], b[m];
  ll cm1[n + 1], cm2[m + 1];
  cm1[0] = 0, cm2[0] = 0;
  for (int i = 0; i <= n; i++) {
    if (i < n)
      a[i] = D();
    if (i)
      cm1[i] = cm1[i - 1] + a[i - 1];
  }

  for (int i = 0; i <= m; i++) {
    if (i < m)
      b[i] = D();
    if (i)
      cm2[i] = cm2[i - 1] + b[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n && cm1[i] <= k; i++) {
    if (cm1[i] > k)
      break;
    for (int j = 0; j <= m && (cm2[j] + cm1[i]) <= k; j++) {
      if (cm2[j] + cm1[i] > k)
        break;
      ans = max(ans, i + j);
    }
  }
  cout << ans;
}