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

/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __
.' ____ \\ [  |      (_)                [  |
| (___ \\_| | |--.   __   _ .--.   .--.  | |.--.   __   _
 _.____`.  | .-. | [  | [ `.-. |/ .'`\\ \\| '/'`\\ \\[  | | |
| \\____) | | | | |  | |  | | | || \\__. ||  \\__/ | | \\_/ |,
 \\______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/

*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {
  return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
}
inline bool inside(int y, int x, int H, int W) {
  return (y >= 0 && x >= 0 && y < H && x < W);
}

/* }}} */

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

  for (int n, k; cin >> n >> k, n || k;) {
    vi sum(n + 1, 0);
    cin >> sum[1];
    REPS(i, 2, n + 1) cin >> sum[i], sum[i] += sum[i - 1];

    int ans = -INF;
    for (int i = k; i <= n; i++) {
      ans = max(ans, sum[i] - sum[i - k]);
    }
    print(ans);
  }

  return (0);
}

Error: TLE

Fixed submission:

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

// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int, int> pii;

bool is_uruu(int y) { return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)); }

signed main() {
  ios::sync_with_stdio(false);
  int n, k;

  while (cin >> n >> k, n || k) {
    vi a(n);
    REP(i, n) cin >> a[i];
    int m = 0;
    REP(i, n - k + 1) {
      int sum = 0;
      for (int j = 0; j < k; j++) {
        sum += a[i + j];
      }
      m = max(m, sum);
    }
    print(m);
  }
  return (0);
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long int sum, k, n, num[200000], to;

int main() {

  while (1) {

    long long int ans = -1000000000;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    for (int i = 0; i < k; i++) {
      sum += num[i];
    }

    for (int i = k; i < n; i++) {
      if (ans < sum)
        ans = sum;
      sum -= num[to++];
      sum += num[i];
    }

    cout << ans << endl;

    sum = 0;
    ans = 0;
    to = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

long long int sum, k, n, num[200000];

int main() {

  while (1) {

    long long int ans = -100000000000;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

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

    cout << ans << endl;
  }

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

// ruiseki-wa
#include <algorithm>
#include <iostream>
using namespace std;

int sum[100010];
int main(void) {
  int n, k;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int i = 0; i < n; i++)
      sum[i + 1] =
          sum[i] + a[i]; // sum[i] := a[0]??????a[i-1]?????§??????(sum[0]=0)

    int ans = sum[k] - sum[0];
    for (int i = 0; i < n - k; i++)
      ans = max(ans, sum[i + 1 + k] - sum[i + 1]);
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;

int main(void) {
  int n, k;
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      break;

    int a[n];
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);
    int ans, sum;
    ans = -114514;
    for (int i = 0; i < n - k + 1; i++) {
      sum = 0;
      for (int j = i; j < i + k; j++) {
        sum += a[j];
      }
      ans = max(ans, sum);
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
using namespace std;
int main(void) {
  while (1) {
    int num[100000] = {0};
    int sum = 0;
    int ma = -100000;
    int n, k;
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;

    for (int i = 0; i < n; i++) {
      scanf("%d", &num[i]);
      if (i < k)
        sum += num[i];
    }
    ma = max(sum, ma);
    for (int i = 0; i < n - k; i++) {
      sum += num[k + i] - num[i];
      ma = max(sum, ma);
    }
    printf("%d\\n", ma);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int num[100001];
int main(void) {
  int n, k;
  while (scanf("%d%d", &n, &k), n + k) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &num[i]);
    }
    int ma = -200000001;
    for (int i = 0; i <= n - k; i++) {
      int part_ma = 0;
      for (int j = i; j < i + k; j++) {
        part_ma += num[j];
      }
      if (ma > part_ma)
        ma = part_ma;
    }
    printf("%d\\n", ma);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

long long int re[100001];

int main() {
  int n, k, i;
  long long c;
  re[0] = 0;
  while (0 <= scanf("%d%d", &n, &k)) {
    if (n == 0 && k == 0)
      break;

    for (i = 1; i <= n; i++) {
      scanf("%lld", &c);
      re[i] = re[i - 1] + c;
    }
    c = re[k];
    for (i = 1; i + k - 1 <= n; i++) {
      if (c < re[i + k - 1] - re[i - 1])
        c = re[i + k - 1] - re[i - 1];
    }
    printf("%lld\\n", c);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int re[10001];

int main() {
  int n, k, i, j, c;
  re[0] = 0;
  while (0 <= scanf("%d%d", &n, &k)) {
    if (n == 0 && k == 0)
      break;

    for (i = 1; i <= n; i++) {
      scanf("%d", &c);
      re[i] = re[i - 1] + c;
    }
    c = re[k];
    for (i = 1; i + k - 1 <= n; i++) {
      if (c < re[i + k - 1] - re[i - 1])
        c = re[i + k - 1] - re[i - 1];
    }
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
// 直接計算型
/*int MAX(int *num,int n,int k){
        int i,j,now,max = 0;
        for(i = 0;i < k;i++){
                max += num[i];
        }
        for(i = 1;i < n-k;i++){
                now = 0;
                for(j = 0;j < k;j++){
                        now += num[i+j];
                }
                if(max < now)
                        max = now;
        }
        return max;
}*/
// 更新書き換え型
int MAX(int *num, int n, int k) {
  int i, now, max = 0;
  for (i = 0; i < k; i++) {
    max += num[i];
  }
  now = max;
  for (i = 0; i < n - k; i++) {
    now += num[i + k] - num[i];
    if (max < now)
      max = now;
  }
  return max;
}
int main() {
  int n, k, max;
  int *num;
  int i;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    num = new int[n];
    for (i = 0; i < n; i++) {
      scanf("%d", num + i);
    }
    max = MAX(num, n, k);
    printf("%d\\n", max);
    delete[] num;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int MAX(int *num, int n, int k) {
  int i, j, now, max = 0;
  for (i = 0; i < k; i++) {
    max += num[i];
  }
  for (i = 1; i < n - k; i++) {
    now = 0;
    for (j = 0; j < k; j++) {
      now += num[i + j];
    }
    if (max < now)
      max = now;
  }
  return max;
}
// 更新書き換え型
/*int MAX(int *num,int n,int k){
        int i,now,max = 0;
        for(i = 0;i < k;i++){
                max += num[i];
        }
        now = max;
        for(i = 0;i < n-k;i++){
                now += num[i+k]-num[i];
                if(max < now)
                        max = now;
        }
        return max;
}*/
int main() {
  int n, k, max;
  int *num;
  int i;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    num = new int[n];
    for (i = 0; i < n; i++) {
      scanf("%d", num + i);
    }
    max = MAX(num, n, k);
    printf("%d\\n", max);
    delete[] num;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int i, j, n, k, a[100000], b[100000], s, max;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    max = 0;
    s = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];

      s += a[i];
      b[i] = a[i];
      if (i >= k - 1) {
        if (max < s)
          max = s;
        s -= b[i - (k - 1)];
      }
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int i, j, n, k, a[100000], b[100000], s, max;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    max = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];

      if (i >= k - 1) {
        s = a[i];
        for (int l = 1; l < k; l++)
          s += a[i - l];
        if (max < s)
          max = s;
      }
    }
    cout << max << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  while (n != 0 || k != 0) {
    int i = 0, a[n], S[n - 1];
    S[0] = 0;
    while (i < n) {
      cin >> a[i];
      if (i >= 1)
        S[i] = S[i - 1] + a[i - 1];
      i++;
    }
    i = 0;
    int m = S[k] - S[0];
    while (k + i < n) {
      if (m < S[i + k] - S[i])
        m = S[i + k] - S[i];
      i++;
    }
    cout << m << endl;
    cin >> n >> k;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  while (n != 0 || k != 0) {
    int i = 0, a[100000], S[100000];
    S[0] = 0;
    while (i < n) {
      cin >> a[i];
      if (i >= 1)
        S[i] = S[i - 1] + a[i - 1];
      i++;
    }
    int q = i;
    i = 0;
    int m = a[0];
    while (k + i <= q) {
      if (m > S[i + k - 1] - S[i])
        m = S[i + k - 1] - S[i];
      i++;
    }
    cout << m << endl;
  }
  cin >> n >> k;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n, k, ma;
int main() {
  for (;;) {
    int num[100001] = {0}, all = 0;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> num[i];
    }
    for (int i = 0; i < n - k; i++) {
      if (i == 0) {
        for (int j = 0; j < k; j++) {
          all += num[i + j];
          ma = all;
        }
        continue;
      }
      all = all - num[i - 1] + num[i + k - 1];
      ma = max(ma, all);
    }
    cout << ma << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n, k, ma;
int main() {
  for (;;) {
    int num[100001] = {0};
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> num[i];
    }
    for (int i = 0; i < n - k; i++) {
      int all = 0;
      for (int j = 0; j < k; j++) {
        all += num[i + j];
      }
      if (i == 0)
        ma = all;
      ma = max(ma, all);
    }
    cout << ma << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;

  while (cin >> n >> k, n | k) {
    int sum = 0;
    int array[n];

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

    int res = sum;
    for (int i = k; i < n; i++) {
      sum += array[i];
      sum -= array[i - k];
      res = max(res, sum);
    }
    cout << res << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  int i, i2, n, k, a[5001], max = -100000000, sum;
  cin >> n >> k;
  while (n != 0) {
    for (i = 1; i <= n; i++)
      cin >> a[i];
    for (i = 1; i <= n - k + 1; i++) {
      sum = 0;
      for (i2 = i; i2 < i + k; i2++)
        sum += a[i2];
      if (sum > max) {
        max = sum;
      }
    }
    cout << max << endl;
    cin >> n >> k;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {

  int n, k, ans = 0, ans2 = 0, mx = 0;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    int num[n];
    // for(int y=0;y<n;y++){
    //   scanf("%d",&num[y]);
    //}
    for (int a = 0; a < k; a++) {
      cin >> num[a];
      ans += num[a];
    }
    mx = ans;
    for (int j = k; j < n; j++) {
      cin >> num[j];
      ans2 = ans - num[j - k] + num[j];
      if (mx <= ans2) {
        mx = ans2;
      }
      ans = ans2;
      ans2 = 0;
    }
    printf("%d\\n", mx);
    mx = 0;
    ans = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int n, k, ans = 0, ans2;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    int num[n];
    for (int y = 0; y < n; y++) {
      scanf("%d", &num[y]);
      if (y >= k) {
        for (int a = 0; a < k; a++) {
          ans += num[y - k + a];
        }
        if (ans2 < ans) {
          ans2 = ans;
        }
        ans = 0;
      }
    }
    printf("%d\\n", ans2);
  }

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

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

int main() {
  int n, m;
  while (cin >> n >> m, n, m) {
    int ans = 0;
    queue<int> que;
    for (int i = 0, num; i < m; i++) {
      cin >> num;
      que.push(num);
      ans += num;
    }
    for (int i = m, num, sum = ans - que.front(); i < n; i++) {
      que.pop();
      cin >> num;
      sum += num;
      ans = max(ans, sum);
      sum -= que.front();
      que.push(num);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k, sum = 0, num, box[10000], ans = 0;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    if (n == k) {
      for (int i = 0; i < n; i++) {
        cin >> num;
        ans += num;
      }
    } else {
      for (int i = 0; i < n; i++) {
        cin >> num;
        if (i < k) {
          sum += num;
          box[i] = num;
        } else if (i >= k) {
          if (sum - box[0] + num > ans)
            ans = sum - box[0] + num;
          sum += num - box[0];
          for (int j = 0; j < k; j++) {
            if (j == k - 1) {
              box[j] = num;
            } else
              box[j] = box[j + 1];
          }
        }
      }
    }
    cout << ans << endl;
    ans = 0;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n, k;
  long long data[100000];
  long long sum[100000];
  while (cin >> n >> k, n | k) {
    for (int i = 0; i < n; i++) {
      cin >> data[i];
    }
    for (int i = 1; i < n; i++) {
      data[i] += data[i - 1];
    }
    long long ans = 0;
    for (int i = k; i < n; i++) {
      ans = max(ans, data[i] - data[i - k]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define N 100001
using namespace std;
int main() {
  int n, k, data[N], maxv, sum, i, j;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (i = 0; i < n; i++)
      cin >> data[i];
    maxv = -2000000000;
    for (i = 0; i < n; i++) {
      sum = 0;
      if (i <= n - k) {
        for (j = i; j < i + k; j++) {
          sum += data[j];
        }
        maxv = max(maxv, sum);
      }
    }
    cout << maxv << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  long long n, k;
  while (1) {
    cin >> n >> k;
    if (!n && !k)
      break;
    int data[n];
    long long sum[n - k + 1];
    sum[0] = 0;
    rep(i, n) {
      cin >> data[i];
      if (i < k)
        sum[0] += data[i];
    }
    rep(i, n - k) { sum[i + 1] = sum[i] + data[i + k] - data[i]; }
    sort(sum, sum + n - k + 1);
    cout << sum[n - k] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  long long n, k;
  while (1) {
    cin >> n >> k;
    if (!n && !k)
      break;
    vector<long long> sum;
    long long num[n];
    rep(i, n) cin >> num[i];
    rep(i, n - k + 1) {
      long long alt = 0;
      loop(j, i, i + k / 2 + 1) {
        alt += num[j];
        if (j != (i + k - 1 - j))
          alt += num[i + k - 1 - j];
      }
      sum.push_back(alt);
    }
    sort(sum.begin(), sum.end());
    cout << sum[sum.size() - 1] << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;
  while (cin >> n >> k) {
    int total[100010] = {0}, ip[100010] = {0};
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> ip[i];
      if (i == k - 1) {
        for (int j = 0; j < k; j++) {
          total[i] += ip[i - j];
        }
      }
      if (i > k - 1) {
        total[i] = total[i - 1] - ip[i - k] + ip[i];
      }
    }
    sort(total, total + n, greater<int>());
    cout << total[0] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main() {
  while (1) {
    int n = 0, k = 0, num[100010] = {0}, ans = 0, sum = 0;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> num[i];
      if (i < k) {
        sum += num[i];
      }
    }
    for (int i = 1; i < n - 2; i++) {
      int s;
      s = sum - num[i - 1] + num[i + k - 1];
      sum = s;
      if (sum > ans)
        ans = sum;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  while (n != 0 || k != 0) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a.at(i);
    }
    vector<int> S(n + 1);
    S.at(0) = 0;
    for (int i = 0; i < n; i++) {
      S.at(i + 1) = S.at(i) + a.at(i);
    }
    int ans = 0;
    for (int i = 0; i + k < n + 1; i++) {
      if (S.at(i + k) - S.at(i) > ans)
        ans = S.at(i + k) - S.at(i);
    }
    cout << ans << endl;
    cin >> n >> k;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  while (n != 0 || k != 0) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a.at(i);
    }
    vector<int> S(n + 1);
    S.at(0) = 0;
    for (int i = 0; i < n + 1; i++) {
      S.at(i + 1) = S.at(i) + a.at(i);
    }
    int ans = 0;
    for (int i = 0; i + k < n + 2; i++) {
      if (S.at(i + k) - S.at(i) > ans)
        ans = S.at(i + k) - S.at(i);
    }
    cout << ans << endl;
    cin >> n >> k;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int serchn, numn;
  for (int a = 0;; a++) {
    cin >> numn >> serchn;
    if (numn == 0 && serchn == 0) {
      break;
    }
    int outp = 0;
    int gh = 0;
    vector<int> num(numn, 0);
    for (int n = 0; n < numn; n++) {
      cin >> num[n];
    }
    for (int n = 0; n < serchn; n++) {
      outp += num[n];
    }
    gh = outp;
    for (int a = 0, b = serchn; b < numn; a++, b++) {
      gh += num[b];
      gh -= num[a];
      if (gh > outp)
        outp = gh;
    }
    cout << outp << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int serchn, numn;
  int gh = 0;
  vector<int> outp;
  for (int a = 0;; a++) {
    cin >> numn >> serchn;
    if (numn == 0 && serchn == 0) {
      break;
    }
    outp.resize(a + 1, 0);
    outp[a] = 0;
    gh = 0;
    vector<int> num(numn, 0);
    for (int n = 0; n < numn; n++) {
      cin >> num[n];
    }
    for (int n = 0; n < serchn; n++) {
      outp[a] += num[n];
    }
    gh = outp[a];
    int b = serchn;
    for (int a = 0; b < numn; a++) {
      gh += num[b];
      gh -= num[a];
      if (gh > outp[a]) {
        outp[a] = gh;
      }
      b += 1;
    }
  }
  for (int b = 0; b < outp.size(); b++) {
    cout << outp[b] << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    ll a[100001];
    REP(i, n) { cin >> a[i]; }
    REP(i, n - 1) { a[i + 1] += a[i]; }
    ll ans = -1000000000000000;
    FOR(i, k, n) { ans = max(ans, a[i] - a[i - k]); }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    ll a[10001];
    REP(i, n) { cin >> a[i]; }
    REP(i, n - 1) { a[i + 1] += a[i]; }
    ll ans = -1000000000000000;
    FOR(i, k, n) { ans = max(ans, a[i] - a[i - k]); }
    cout << ans << endl;
  }
  return 0;
}