alexjercan/bugnet huggingface dataset:
Problem p00022 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int n;
  int buf[5000];
  long goukei;
  long max;

  int i, j;

  while (1) {
    goukei = 0;
    max = -100001;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d", &buf[i]);
    }

    for (i = 0; i < n; i++) {
      goukei = 0;
      for (j = i; j < n; j++) {
        goukei += buf[j];
        if (goukei > max) {
          max = goukei;
        }
      }
    }

    printf("%ld\\n", max);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int n;
  int buf[5000];
  long goukei;
  long max;

  int i, j, k;

  while (1) {
    goukei = 0;
    max = 0;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d", &buf[i]);
    }

    for (i = 0; i < n; i++) {
      for (j = 0; j < n - i; j++) {
        for (k = j; k <= j + i; k++) {
          goukei += buf[k];
        }
        if (goukei > max) {
          max = goukei;
        }
        goukei = 0;
      }
    }

    printf("%d\\n", max);
  }

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

#include <iostream>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main() {
  int n;
  while (cin >> n && n != 0) {
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    vector<int> sum(n);
    sum[0] = a[0];
    FOR(i, 1, n) sum[i] = sum[i - 1] + a[i];
    int ret = sum[0];
    FOR(i, -1, n)
    FOR(j, i + 1, n) ret =
        i > -1 ? max(ret, sum[j] - sum[i]) : max(ret, sum[j]);
    cout << ret << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main() {
  int n;
  while (cin >> n && n != 0) {
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int ret = 0;
    REP(i, a.size()) {
      FOR(j, i, a.size()) {
        int sum = 0;
        FOR(k, i, j + 1) sum += a[k];
        ret = max(ret, sum);
      }
    }
    cout << ret << endl;
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, a[5001];
  int ans;
  a[0] = 0;
  while (cin >> n && n) {
    ans = INT_MIN;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] += a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j++) {
        ans = max(ans, a[j] - a[i - 1]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int>> vpii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;

int main() {
  int N;
  int x;
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    int index = 0;
    vl v(N * N), sum(N);
    FOR(i, 1, N + 1) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    rep(i, N + 1) {
      FOR(j, i + 2, N + 1) {
        v[index] = sum[j] - sum[i];
        index++;
      }
    }
    cout << *max_element(all(v)) << endl;
  }
}
Problem p00022 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int>> vpii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main() {
  int N;
  int ans = 0;
  while (cin >> N && N) {
    int index = 0;
    ans = INT_MIN;
    FOR(i, 1, N + 1) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    FOR(i, 1, N + 1) {
      FOR(j, i, N + 1) { ans = max(ans, sum[j] - sum[i - 1]); }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int>> vpii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[2000];
int main() {
  int N;
  int ans = 0;
  while (cin >> N && N) {
    int index = 0;
    ans = INT_MIN;
    FOR(i, 1, N + 1) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    FOR(i, 1, N + 1) {
      FOR(j, i, N + 1) { ans = max(ans, sum[j] - sum[i - 1]); }
    }
    cout << ans << endl;
  }
}
Problem p00022 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int>> vpii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main() {
  int N;
  int ans = 0;
  while (cin >> N && N) {
    int index = 0;
    ans = INT_MIN;
    FOR(i, 1, N + 1) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    FOR(i, 1, N + 1) {
      FOR(j, i, N + 1) { ans = max(ans, sum[j] - sum[i - 1]); }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int>> vpii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[2500];
int main() {
  int N;
  int ans = 0;
  while (cin >> N && N) {
    int index = 0;
    ans = INT_MIN;
    FOR(i, 1, N + 1) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    FOR(i, 1, N + 1) {
      FOR(j, i, N + 1) { ans = max(ans, sum[j] - sum[i - 1]); }
    }
    cout << ans << endl;
  }
}
Problem p00022 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>

using namespace std;

template <typename Type> long long Maximum_Sum_Sequence(Type N[], int size) {
  long long max = LLONG_MIN;

  for (int i = 0; i < size; i++) {
    long long sum = 0;

    for (int j = i; j < size; j++) {
      sum += N[j];

      if (sum > max) {
        max = sum;
      }
    }
  }

  return max;
}

int main() {
  const int DATASETS = 100;

  int n[DATASETS], a[DATASETS][5000], c = 0;

  while (true) {
    cin >> n[c];

    if (n[c] == 0) {
      break;
    }

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

    c++;
  }

  for (int i = 0; i < c; i++) {
    cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <climits>
#include <iostream>

using namespace std;

template <typename Type> long long Maximum_Sum_Sequence(Type N[], int size) {
  long long max = LLONG_MIN;

  for (int i = 0; i < size; i++) {
    long long sum = 0;

    for (int j = i; j < size; j++) {
      sum += N[j];

      if (sum > max) {
        max = sum;
      }
    }
  }

  return max;
}

int main() {
  const int DATASETS = 20000;

  int n[DATASETS], a[DATASETS][5000], c = 0;

  while (true) {
    cin >> n[c];

    if (n[c] == 0) {
      break;
    }

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

    c++;
  }

  for (int i = 0; i < c; i++) {
    cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
  }

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

#include <iostream>
using namespace std;

int main(void) {

  int a[5001];
  for (int i = 0; i < 5001; i++)
    a[i] = 0;

  int n;
  while (cin >> n) {

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

    int ans = -999999;
    int sum = 0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < (n - i); j++) {
        sum = sum + a[i + j];
        if (sum > ans)
          ans = sum;
      }
      sum = 0;
    }

    cout << ans << endl;

    for (int i = 0; i < 5001; i++)
      a[i] = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int a[5001];

int sumation(int i, int n) {
  int res = 0;
  for (int k = 0; k < n; k++) {
    res += a[i + k];
  }
  return res;
}

int main(void) {

  for (int i = 0; i < 5001; i++)
    a[i] = 0;

  int n;
  while (cin >> n) {

    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      int tmp;
      cin >> tmp;
      a[i] = tmp;
    }

    int res = 0;
    for (int i = 1; i <= n; i++) {
      int rres = 0;
      for (int j = 0; j < (n - i + 1); j++) {
        if (rres < sumation(j, i))
          rres = sumation(j, i);
      }
      if (res < rres)
        res = rres;
    }
    cout << res << endl;

    for (int i = 0; i < 5001; i++)
      a[i] = 0;
  }

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

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define REP(i, x, y) for (int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int, int> Pi;

const int INF = 100000000;
const long long int INF_ = 1000000000000000000;

int main() {
  int N;
  while (cin >> N && N) {
    vector<int> A(N + 1);
    REP(i, 1, N + 1) cin >> A[i];
    vector<int> s(N + 1);
    REP(i, 1, N + 1) s[i] = s[i - 1] + A[i];
    lli ans = -INF_;
    REP(i, 0, N + 1)
    REP(j, i + 1, N + 1) if (ans < s[j] - s[i]) ans = s[j] - s[i];
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define REP(i, x, y) for (int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int, int> Pi;

const int INF = 100000000;
const long long int INF_ = 1000000000000000000;

int main() {
  int N;
  while (cin >> N && N) {
    vector<int> A(N + 1);
    REP(i, 1, N + 1) cin >> A[i];
    vector<int> s(N);
    REP(i, 1, N + 1) s[i] = s[i - 1] + A[i];
    lli ans = -INF_;
    REP(i, 0, N + 1)
    REP(j, i + 1, N + 1) if (ans < s[j] - s[i]) ans = s[j] - s[i];
    cout << ans << endl;
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

template <typename T> T m(T a, T b) { return a > b ? a : b; }

vector<int> v(5001);

int main(void) {
  int N;
  while (true) {
    cin >> N;
    if (N == 0)
      break;

    for (int i = 0; i < N; i++)
      cin >> v[i];

    long long mx = -100000L;

    for (int i = 0; i < N; i++) {
      long long tmp = 0L;
      for (int j = i; j < N; j++) {
        tmp += v[j];
        mx = m(mx, tmp);
      }
    }
    cout << mx << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

template <typename T> T m(T a, T b) { return a > b ? a : b; }

int main(void) {
  freopen("i.in", "r", stdin);
  int N;
  while (true) {
    cin >> N;
    if (N == 0)
      break;
    vector<int> v(N);

    for (int i = 0; i < N; i++)
      cin >> v[i];

    long long mx = -100000L;

    for (int i = 0; i < N; i++) {
      long long tmp = 0L;
      for (int j = i; j < N; j++) {
        tmp += v[j];
        mx = m(mx, tmp);
      }
    }
    cout << mx << endl;
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  int a[5001];
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int kkk = 1; kkk <= n; kkk++) {
      a[kkk] = 0;
    }
    for (int kk = 1; kk <= n; kk++) {
      cin >> a[kk];
    }
    int high = a[1], sum = 0;
    for (int i = 1; i <= n; i++) {
      sum = sum + a[i];
      if (sum >= high) {
        high = sum;
      }
      if (sum <= 0) {
        sum = 0;
      }
    }
    cout << high << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, b;
  int a[5001];
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int kkk = 1; kkk <= n; kkk++) {
      a[kkk] = 0;
    }
    for (int kk = 1; kk <= n; kk++) {
      cin >> a[kk];
    }
    int high = a[1];
    for (int k = 1; k <= n; k++) {
      for (int l = k; l <= n; l++) {
        int sum = 0;
        for (int m = k; m <= l; m++) {
          sum = sum + a[m];
          if (sum >= high) {
            high = sum;
          }
        }
      }
    }
    cout << high << endl;
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> cum;
  int n, sum, tmp;

  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }

    cum.resize(n + 1);
    cum[0] = 0;
    sum = (-2147483647);

    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      cum[i] = cum[i - 1] + tmp;
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        sum = max(sum, cum[j] - cum[i]);
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

/*
        0022:Maximum Sum Sequence
*/
#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  while (1) {
    int n, ans = -10000;
    int array[5000];

    cin >> n;
    if (n == 0) {
      break;
    }

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

    /*長さmlxの範囲を変えていく*/
    for (int mxl = 0; mxl < n; mxl++) {
      /*mlxの範囲内の最初の項（左端）をさす*/
      for (int i = 0; i < n - mxl; i++) {
        /*mlxの範囲の和を求める*/
        int sSum = 0;
        for (int j = 0; j <= mxl; j++) {
          sSum += array[i + j];
        }
        ans = max(ans, sSum);
      }
    }

    cout << ans << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
int n, a[5008];
int b[5008];

int solve() {
  int res = -100001;
  for (int i = 0; i <= n; i++) {
    for (int j = n; j > i; j--) {
      res = max(res, b[j] - b[i]);
    }
  }
  return res;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i + 1]);
    }

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

    printf("%d\\n", solve());
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;
int n, a[5008];

int solve() {
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int tmp = 0;
      for (int p = i; p <= j; p++) {
        tmp += a[p];
      }
      res = max(res, tmp);
    }
  }
  return res;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }

    printf("%d\\n", solve());
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <stack>
#include <vector>
#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b) { return a.real() * b.real() + a.imag() * b.imag(); }

int main() {
  int N;
  while (scanf(" %d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    vector<int> series(N);

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

    int mx = -1000000000;
    for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
        sum += series[j];

        mx = max(mx, sum);
      }
    }
    printf("%d\\n", mx);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <stack>
#include <vector>
#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b) { return a.real() * b.real() + a.imag() * b.imag(); }

int main() {
  int N;
  while (scanf(" %d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    vector<int> series(N);

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

    int mx = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        int sum = 0;
        for (int k = i; k <= j; k++) {
          sum += series[k];
        }
        // printf("sum = %d\\n", sum);
        mx = max(mx, sum);
      }
    }
    printf("%d\\n", mx);
  }
  return 0;
}
Problem p00022 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;

  while (cin >> n, n != 0) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int minimum = 0;
    int x = 0;
    int maximum = -9999999;
    for (int i = 0; i < a.size(); i++) {
      x += a[i];
      maximum = max(maximum, x - minimum);
      minimum = min(minimum, x);
    }

    cout << maximum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;

  while (cin >> n, n != 0) {
    vector<int> a(n);
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }

    int minimum = 0;
    int x = 0;
    int maximum = -(1 << 29);
    for (int i = 0; i <= a.size(); i++) {
      x += a[i];
      maximum = max(maximum, x - minimum);
      minimum = min(minimum, x);
    }

    cout << maximum << endl;
  }

  return 0;
}