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

#include <algorithm>
#include <iostream>

using namespace std;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  int n, k, input[5000];
  while (cin >> n >> k, n | k) {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      cin >> input[i];
      if (i < k)
        sum += input[i];
    }
    int i, j, ans = sum;
    i = 0;
    j = k - 1;
    while (j < n - 1) {
      sum -= input[i++];
      sum += input[++j];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a[100010], n, k;
  while (cin >> n >> k, n || k) {
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int mx = -1;
    int sum = 0;
    for (int i = 0; i < k; i++)
      sum += a[i];
    mx = sum;
    for (int i = k; i < n; i++) {
      sum -= a[i - k];
      sum += a[i];
      mx = max(mx, sum);
    }
    cout << mx << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[100010], n, k;
  while (cin >> n >> k, n || k) {
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int mx = -1;
    for (int i = 0; i <= n - k; i++) {
      int sum = 0;
      for (int j = i; j < i + k; j++)
        sum += a[j];
      mx = max(mx, sum);
    }
    cout << mx << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

int N, K;
int a[100001];

void solve() {
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i + 1]);
    a[i + 1] += a[i];
  }
  int ma = 0;
  for (int i = K; i <= N; i++)
    ma = max(ma, a[i] - a[i - K]);
  printf("%d\\n", ma);
}
int main() {
  while (scanf("%d%d", &N, &K), N || K)
    solve();
}

Error: 0

Fixed submission:

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

int N, K;
int a[10001];

void solve() {
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i + 1]);
    a[i + 1] += a[i];
  }
  int ma = 0;
  for (int i = K; i <= N; i++)
    ma = max(ma, a[i] - a[i - K]);
  printf("%d\\n", ma);
}
int main() {
  while (scanf("%d%d", &N, &K), N || K)
    solve();
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  long long int ans;
  long long int kans;
  int num[100001];
  int n, k;
  int a, b;
  ans = 0;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    for (a = 0; a < n; a++)
      scanf("%d", &num[a]);
    for (a = 0; a < n - k; a++) {
      kans = 0;
      for (b = 0; b < k; b++) {
        kans += num[a + b];
      }
      ans = max(ans, kans);
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

#define MAX 100000

int main() {

  int n, k, a[MAX];
  long long num, max;

  while (1) {

    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    num = 0;
    for (int j = 0; j < k; j++) {
      num += a[j];
    }
    max = num;

    for (int i = 0; i < n - k; i++) {
      num -= a[i];
      num += a[i + k];
      max = (max < num) ? num : max;
    }

    cout << max << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

#define MAX 100000
#define INF (10000 * 100000 + 1)
int main() {

  std::ios_base::sync_with_stdio(false);

  int n, k, a[MAX];
  long long num, max;

  while (1) {

    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    max = -1 * INF;
    for (int i = 0; i <= n - k; i++) {
      num = 0;
      for (int j = 0; j < k; j++) {
        num += a[i + j];
      }
      max = (max < num) ? num : max;
    }
    cout << max << endl;
  }

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

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

int main() {
  // cout << "aaa" << endl;
  while (true) {
    ll n, k;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    vector<ll> A(n);
    for (ll i = 0; i < n; i++) {
      cin >> A[i];
    }

    vector<ll> s(n);
    for (ll i = 0; i < n; i++) {
      s[i + 1] = s[i] + A[i];
    }
    ll mx = (1LL << 60) * -1;

    for (ll i = 0; i < n - k; i++) {
      mx = max(mx, s[i + k] - s[i]);
    }
    cout << mx << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int tmp;
  cin >> tmp >> tmp;

  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s[i + 1] = s[i] + A[i];
  }
  int mx = (1 << 21) * -1;

  for (int i = 0; i < n - k; i++) {
    mx = max(mx, s[i + k] - s[i]);
  }
  cout << mx << endl;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n, k;
  while (cin >> n >> k, n + k) {
    int max_sum, sum = 0, data[100000];

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

    for (int i = k; i < n; i++) {
      cin >> data[i];
      sum -= data[i - k];
      sum += data[i];
      max_sum = max(max_sum, sum);
    }

    cout << max_sum << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {

  int n, k;
  while (cin >> n >> k, n + k) {
    int max_sum, sum, data[100000];

    cin >> data[0] >> data[1] >> data[2];
    max_sum = sum = data[0] + data[1] + data[2];

    for (int i = k; i < n; i++) {
      cin >> data[i];
      sum -= data[i - k];
      sum += data[i];
      max_sum = max(max_sum, sum);
    }

    cout << max_sum << 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 a[100005];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int ans = 0;
    for (int i = 0; i <= n - k; i++) {
      int s = 0;
      for (int j = 0; j < k; j++) {
        s += a[i + j];
      }
      if (s > ans)
        ans = s;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  while (cin >> n >> k, n, k) {

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

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

#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n, k;
  while (scanf("%d %d", &n, &k) && n != 0) {
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);
    int max = 0;
    for (int i = 0; i < k; i++)
      max += a[i];
    int tmp = max;
    for (int i = 0; i < n - k; i++) {
      tmp = tmp - a[i] + a[i + k];
      if (tmp > max)
        max = tmp;
    }
    printf("%d\\n", max);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n, k;
  while (scanf("%d %d", &n, &k) && n != 0) {
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);
    int max = 0;
    for (int i = 0; i < n - k; i++) {
      int tmp = 0;
      for (int j = i; j < i + k; j++) {
        tmp += a[j];
      }
      if (tmp > max)
        max = tmp;
    }
    printf("%d\\n", max);
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int inp[1000000];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 0; i < n; i++) {
      inp[i] = in();
    }
    Int max;
    Int sum = 0;
    int k;
    for (k = 0; k < m; k++) {
      sum += inp[k];
    }
    max = sum;
    for (i = 0; i <= n - m; i++) {
      if (max < sum)
        max = sum;
      sum -= inp[i];
      if (i != n - m)
        sum += inp[i + m];
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int inp[1000000];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 0; i < n; i++) {
      inp[i] = in();
    }
    Int max = -2000000000;
    for (i = 0; i <= n - m; i++) {
      Int sum = 0;
      int k;
      for (k = 0; k < m; k++) {
        sum += inp[i + k];
        // cout<<sum<<endl;
      }
      if (max < sum)
        max = sum;
    }
    cout << max;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  int n, m, a;

  while (cin >> n >> m, n | m) {
    int d[100001] = {};
    cin >> d[0];

    for (int i = 1; i < n; i++) {
      cin >> a;
      d[i] += d[i - 1] + a;
    }
    int MAX = 0;
    for (int i = 0; i < n - m; i++) {
      if (d[i + m] - d[i] > MAX)
        MAX = d[i + m] - d[i];
    }
    cout << MAX << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, m, a;

  while (cin >> n >> m, n | m) {
    int d[10001] = {};
    cin >> d[0];

    for (int i = 1; i < n; i++) {
      cin >> a;
      d[i] += d[i - 1] + a;
    }
    int MAX = 0;
    for (int i = 0; i < n - m; i++) {
      if (d[i + m] - d[i] > MAX)
        MAX = d[i + m] - d[i];
    }
    cout << MAX << endl;
  }

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

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int n, k, max = -1e9, sum = 0;
    cin >> n >> k;
    if (n == 0)
      break;
    int ar[n];
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      ar[i] = a;
    }

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

    for (int j = 0; j < n - k + 1; j++) {
      if (sum > max)
        max = sum;
      sum = sum + ar[k + j] - ar[j];
    }
    cout << max << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int n, k, max = -1e9, sum = 0;
    cin >> n >> k;
    if (n == 0)
      break;
    int ar[n];
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      ar[i] = a;
    }

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

#include <iostream>
using namespace std;

int main() {
  int n, k, a[100000];
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int s = 0, max;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    max = s;
    for (int i = k; i < n; i++) {
      s += (-a[i - k] + a[i]);
      if (s > max)
        max = s;
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k, a[100000], max = -1000000000;
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n - k + 1; i++) {
      int s = 0;
      for (int j = 0; j < k; j++) {
        s += a[i + j];
      }
      if (s > max)
        max = s;
    }
    cout << max << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

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

#define repeat(n, i) for (int i = 0; i < (n); i++)

int n, k;
vector<int> a;

int solve() {
  int sum = 0, prev_sum = 0;
  for (int i = 0; i < k; i++) {
    prev_sum += a[i];
  }
  int max_sum = prev_sum;
  for (int i = 1; i + k - 1 < n; i++) {
    sum = prev_sum - a[i - 1] + a[i + k - 1];
    if (max_sum < sum)
      max_sum = sum;
    prev_sum = sum;
  }
  return max_sum;
}

int main() {
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    a.clear();
    repeat(n, i) {
      int _a;
      cin >> _a;
      a.push_back(_a);
    }
    cout << solve() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

#define NMAX 5000

int n, k;
int a[NMAX];

int solve() {
  int max_sum = -10000000;
  int sum = 0;
  for (int i = 0; i + k < n; i++) {
    for (int j = i; j < i + k; j++) {
      sum += a[j];
    }
    if (sum > max_sum)
      max_sum = sum;
    sum = 0;
  }
  return max_sum;
}

int main() {
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << solve() << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long ll;

int a[1000000];

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

    ll pre = 0;
    for (int i = 0; i < k; i++) {
      pre += a[i];
    }

    ll ret = pre;
    for (int i = 0; i < n - k; i++) {
      pre = pre - a[i] + a[k + i];
      ret = max(ret, pre);
    }

    cout << ret << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long ll;

int a[10000];

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

    ll pre = 0;
    for (int i = 0; i < k; i++) {
      pre += a[i];
    }

    ll ret = pre;
    for (int i = 0; i < n - k; i++) {
      pre = pre - a[i] + a[k + i];
      ret = max(ret, pre);
    }

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

#include <iostream>
using namespace std;

int main() {
  int n, k, s, ans;
  int a[100001];
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    s = 0;
    for (int i = 0; i < n - k + 1; i++) {
      if (i == 0)
        for (int j = i; j < i + k; j++)
          s += a[j];
      if (i != 0) {
        s -= a[i - 1];
        s += a[i + k - 1];
      }
      if (i == 0)
        ans = s;
      if (s > ans)
        ans = s;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k, s, ans;
  int a[100001];
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int i = 0; i < n - k + 1; i++) {
      s = 0;
      for (int j = i; j < i + k; j++)
        s += a[j];
      if (i == 0)
        ans = s;
      if (s > ans)
        ans = s;
    }
    cout << ans << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) {
    vector<long long> inp;
    long n, k, input;
    cin >> n >> k;
    if (!(n || k))
      break;

    for (long long i = 0; i < n; i++) {
      cin >> input;
      inp.push_back(input);
    }

    int s, sum = 0;
    for (int i = 0; i < k; i++)
      sum += inp[i];
    s = sum;
    for (int i = 0; k < inp.size(); i++, k++) {
      s -= inp[i];
      s += inp[k];
      if (sum < s)
        sum = s;
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  while (cin >> n >> k, n || k) {
    vector<int> a;
    vector<int> s;

    int aa;
    for (int i = 0; i < n; i++) {
      cin >> aa;
      a.push_back(aa);
      s.push_back(0);
    }

    for (int i = 0; i < n - k; i++) {
      for (int j = i; j < i + k; j++) {
        s[i] += a[j];
      }
    }

    sort(s.begin(), s.end(), greater<int>());

    cout << s[0] << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, k;
  while (scanf("%d %d", &n, &k), n && k) {
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &data[i]);
    }
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < k; i++)
      sum += data[i];
    for (int i = k; i < n; i++) {
      sum += data[i] - data[i - k];
      ans = max(ans, sum);
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

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

#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: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 100001

int main() {
  int n, k, a[MAX];

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

    int MX = 0, sum;
    for (int i = k - 1; i < n; i++) {
      sum = 0;
      for (int j = i - k + 1; j <= i; j++) {
        sum += a[j];
      }
      if (MX < sum)
        MX = sum;
    }
    cout << MX << endl;
  }

  return 0;
}