Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(a, b)                                                            \\
  if ((a) > (b))                                                               \\
    (a) = (b);
#define chmax(a, b)                                                            \\
  if ((a) < (b))                                                               \\
    (a) = (b);
#define vi vector<int>
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pf push_front
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a %= b;
  }
  return max(a, b);
}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const long long INF = 1e18 + 10;

/*--------------------------------------------------------------------*/
signed main() {
  int n;
  cin >> n;

  int ans = 0;
  FOR(j, 1, n) {
    int a = n / j;
    ans += a * (a + 1) / 2 * j;
  }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(a, b)                                                            \\
  if ((a) > (b))                                                               \\
    (a) = (b);
#define chmax(a, b)                                                            \\
  if ((a) < (b))                                                               \\
    (a) = (b);
#define vi vector<int>
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pf push_front
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a %= b;
  }
  return max(a, b);
}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

/*--------------------------------------------------------------------*/

signed main() {
  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];

  vi sa(n, 0), sb(m, 0);
  rep(i, n) sa[i] = a[i];
  rep(i, m) sb[i] = b[i];

  FOR(i, 1, n - 1) sa[i] += sa[i - 1];
  FOR(i, 1, m - 1) sb[i] += sb[i - 1];

  int sum = 0;
  int la = -1;
  int lb = 0;
  rep(i, n) {
    if (sum + a[i] <= k) {
      sum += a[i];
      la = i;
    }
  }
  int ans = la + 1; // number

  // cout<<ans<<endl<<endl;

  if (la >= 0)
    rep(j, m) {
      int tmp = sum + b[j];
      while (tmp > k) {
        tmp -= a[la];
        la--;
        if (la < 0)
          break;
      }
      if (la < 0) {
        cout << ans << endl;
        return 0;
      }
      if (tmp <= k) {
        chmax(sum, tmp) chmax(ans, la + 1 + j + 1);
      }

      // cout<<ans<<':'<<sum<<endl;
    }
  cout << ans << endl;

  return 0;
}