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

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#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;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const double EPS = 1e-10;

int main() {
  int N, K, res, max;

  while (cin >> N >> K, N) {
    vi num(N);
    res = 0;

    REP(i, N) { cin >> num[i]; }

    REP(i, K) { res += num[i]; }
    max = res;

    REP(i, N - K) {
      res -= num[i];
      res += num[K + i];

      if (max < res) {
        max = res;
      }
    }

    cout << max << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#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;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const double EPS = 1e-10;

int main() {
  int n, k;
  ll result, tmp;

  while (cin >> n >> k, n) {
    vi nums(n);
    result = -INT_MAX;
    tmp = 0;

    REP(i, n) { cin >> nums[i]; }

    REP(i, n - k) {
      REP(j, k) { tmp += nums[i + j]; }

      if (result < tmp) {
        result = tmp;
      }
    }

    cout << result << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <deque>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int ini[100001];
int main() {
  while (1) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0)
      break;
    rep(i, n) { scanf("%d", &ini[i]); }

    int sum = 0;
    rep(i, m) { sum += ini[i]; }

    int maxi = sum;
    for (int i = m; i < n; i++) {
      sum -= ini[i - m];
      sum += ini[i];
      maxi = max(maxi, sum);
    }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <deque>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int ini[10001];
int main() {
  while (1) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0)
      break;
    rep(i, n) { scanf("%d", &ini[i]); }

    int sum = 0;
    rep(i, m) { sum += ini[i]; }

    int maxi = sum;
    for (int i = m; i < n; i++) {
      sum -= ini[i - m];
      sum += ini[i];
      maxi = max(maxi, sum);
    }

    printf("%d\\n", maxi);
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long int ll;
int main() {
  int n, k;
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0)
      return 0;
    int a[n];
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);
    ll bgs = 0, temp = 0;
    for (int i = 0; i < k; i++)
      temp += a[i];
    bgs = temp;
    for (int i = 1; i <= n - k; i++) {
      temp = temp - a[i - 1] + a[i + k - 1];
      bgs = max(bgs, temp);
    }
    printf("%lld\\n", bgs);
  }
}

Error: TLE

Fixed submission:

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

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int a[100000];
int main() {
  int n, k, best, g;
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    best = 0;
    g = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        g += a[i];
    }
    best = g;
    for (int i = 1; i <= n - k; i++) {
      g += a[i + k - 1] - a[i - 1];
      if (g > best)
        best = g;
    }
    cout << best << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int a[100000];
int main() {
  int n, k, best;
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    best = 0;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int i = 0; i < n - k; i++) {
      int count = 0;
      for (int j = i; j < i + k; j++)
        count += a[j];
      if (best < count)
        best = count;
    }
    cout << best << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int n, k;
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      return 0;
    int a[n];
    for (int i = 0; i < n; i++)
      scanf("%d", a + i);
    int sum = 0, ans = 0;
    for (int i = 0; i + k <= n; i++) {
      if (i == 0) {
        for (int j = 0; j < k; j++)
          sum += a[i + j];
        ans = sum;
      } else {
        sum = sum - a[i - 1] + a[i + k - 1];
        ans = max(ans, sum);
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int a[100000] = {};

signed main() {
  int k;
  int n;

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

    int m = -9999999999;
    int tmp = 0;
    int cnt = 0;

    for (int i = 0; i < n; i++) {
      if (i < k) {
        tmp += a[i];
      } else {
        tmp -= a[i - k];
        tmp += a[i];
        m = max(m, tmp);
      }
    }

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

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

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

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  queue<int> q;
  while (cin >> n >> k, n || k) {
    while (!q.empty())
      q.pop();
    int t, sum = 0, ans = -10000 * 100000;
    for (int i = 0; i < k; i++) {
      cin >> t;
      sum += t;
      q.push(t);
    }
    ans = max(ans, sum);
    for (int i = 0; i < n - k; i++) {
      t = q.front();
      q.pop();
      sum -= t;
      cin >> t;
      sum += t;
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int seq[100000];
int n, k;

int req(int rem, int i) {
  rem -= seq[i];
  rem += seq[i + k];
  return rem;
}
int main() {
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seq[i];
    }
    int rem = 0;
    for (int i = 0; i < k; i++) {
      rem += seq[i];
    }
    int remm = rem;
    for (int i = 0; i < n - k; i++) {
      rem = req(rem, i);
      remm = max(remm, rem);
    }
    cout << remm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int seq[100000];
int n, k;

int req(int i) {
  int sum = 0;
  for (int j = 0; j < k; j++) {
    sum += seq[i + j];
  }
  return sum;
}
int main() {
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seq[i];
    }
    int rem = -100000000;
    for (int i = 0; i < n - k + 1; i++) {
      rem = max(rem, req(i));
    }
    cout << rem << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    int nums[n];
    for (int i = 0; i < n; i++) {
      cin >> nums[i];
      if (i != 0) {
        nums[i] += nums[i - 1];
      }
    }

    int max = nums[m - 1];
    for (int i = 1; i < n - m; i++) {
      if (nums[m - 1 + i] - nums[i - 1] > max) {
        max = nums[m - 1 + i] - nums[i - 1];
      }
    }
    cout << max << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  vector<int> ans;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    int nums[n];
    for (int i = 0; i < n; i++) {
      cin >> nums[i];
    }
    int max = 0;
    for (int i = 0; i < m; i++) {
      i += nums[i];
    }
    for (int i = 1; i < n - m + 1; i++) {
      int sum = 0;
      int k = i;
      for (int j = 0; j < m; j++) {
        sum += nums[k + j];
      }
      if (sum > max) {
        max = sum;
      }
    }
    ans.push_back(max);
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int a[100001];
int main(void) {
  int n, k, sum, max = 0, i, j;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i <= n - k; i++) {
      sum = 0;
      if (i + k <= n) {
        for (j = i; j < i + k; j++) {
          sum += a[j];
        }
        if (max < sum) {
          max = sum;
        }
      }
    }
    printf("%d\\n", max);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, k, a[5000], sum, max = 0, i, j;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i <= n - k; i++) {
      sum = 0;
      if (i + k <= n) {
        for (j = i; j < i + k; j++) {
          sum += a[j];
        }
        if (max < sum) {
          max = sum;
        }
      }
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> sum;
  int n, m, x, max;
  while (cin >> n >> m, n || m) {
    cin >> x;
    sum.push_back(0);
    sum.push_back(x);
    max = -1000000;
    for (int i = 2; i <= n; i++) {
      cin >> x;
      sum.push_back(sum[i - 1] + x);
    }
    for (int i = 0; i < n - m + 1; i++) {
      if (sum[m + i] - sum[i] > max)
        max = sum[m + i] - sum[i];
    }
    cout << max << endl;
    sum.clear();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> sum;
  int n, m, x, max;
  while (cin >> n >> m, n || m) {
    cin >> x;
    sum.push_back(0);
    sum.push_back(x);
    max = -1000000;
    for (int i = 2; i <= n; i++) {
      cin >> x;
      sum.push_back(sum[i - 1] + x);
    }
    for (int i = 0; i < n; i++) {
      if (sum[m + i] - sum[i] > max)
        max = sum[m + i] - sum[i];
    }
    cout << max << endl;
    sum.clear();
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int n, a[100001] = {0}, k, sum, p;
  int i, j, h;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    cin >> a[1];
    for (i = 2; i <= n; i++) {
      cin >> a[i];
      a[i] += a[i - 1];
    }
    sum = a[k];
    for (i = k + 1; i <= n; i++) {
      sum = max(sum, a[i] - a[i - k]);
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int n, a[100001], k, sum, p;
int main() {
  int i, j, h;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    a[i] = 0;
  }
  while (1) {
    cin >> a[1];
    for (i = 2; i <= n; i++) {
      cin >> a[i];
      a[i] += a[i - 1];
    }
    for (i = 1; i <= n; i++) {
      for (j = i; j <= i + k; j++) {
        p = a[i + k] - a[j];
        if (p >= sum) {
          sum = p;
        }
      }
    }
    cout << sum << endl;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (i = 1; i <= n; i++) {
      a[i] = 0;
    }
    cin >> a[1];
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int n, k, a[1000000], top, sum;
  while (1) {
    scanf("%d%d", &n, &k);
    if (n == 0)
      return 0;
    sum = 0;
    for (int i = 0; i < k; i++) {
      scanf("%d", &a[i]);
      sum += a[i];
    }
    top = sum;
    for (int i = k; i < n; i++) {
      scanf("%d", &a[i]);
      sum += a[i];
      sum -= a[i - k];
      if (sum > top)
        top = sum;
    }
    printf("%d\\n", top);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  long long int n, k, a[10], top;
  while (1) {
    scanf("%lld%lld", &n, &k);
    if (n == 0)
      return 0;
    scanf("%lld", &a[0]);
    for (int i = 1; i < k; i++) {
      scanf("%lld", &a[i]);
      a[i] += a[i - 1];
    }
    top = a[k - 1];
    for (int i = k; i < n; i++) {
      scanf("%lld", &a[i]);
      a[i] += a[i - 1];
      a[i] -= a[i - k];
      if (i != k)
        a[i] += a[i - k - 1];
      if (a[i] > top)
        top = a[i];
    }
    printf("%lld\\n", top);
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if ((n | k) == 0) {
      break;
    }
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int *s = new int[n - k + 1];
    s[0] = 0;
    for (int i = 0; i < k; i++) {
      s[0] += a[i];
    }
    int maxS = s[0];
    for (int i = 1; i <= n - k; i++) {
      s[i] = s[i - 1] - a[i - 1] + a[i + k - 1];
      if (maxS < s[i]) {
        maxS = s[i];
      }
    }
    cout << maxS << endl;
    delete[] a;
    delete[] s;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
  int n, k;
  int sum1 = 0, max = 0;
  int now = 0, nextdata, next;
  int *s;
  while (1) {
    sum1 = 0;
    max = 0;
    cin >> n >> k;

    if (n == 0)
      break;

    s = (int *)malloc(sizeof(int) * k);

    int data;
    for (int i = 0; i < k; i++) {
      cin >> data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = k - 1;

    for (int i = 0; i < n - k; i++) {
      cin >> data;
      if (now + 1 == k) {
        next = 0;
        nextdata = s[0];
      } else {
        next = now + 1;
        nextdata = s[next];
      }

      sum1 = sum1 - nextdata + data;
      if (sum1 > max)
        max = sum1;
      now = next;
      s[now] = data;
      /*for(int j = 0; j < k; j++){
        cout << s[j]<<" ";
      }
      cout << endl;*/
    }

    cout << max << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
  int n, k;
  int sum1 = 0, max = 0;
  int now = 0, nextdata, next;
  int *s;
  while (1) {
    sum1 = 0;
    max = 0;
    cin >> n >> k;

    if (n == 0)
      break;

    s = (int *)malloc(sizeof(int) * k);

    int data;
    for (int i = 0; i < k; i++) {
      cin >> data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n - 1;

    for (int i = 0; i < n - k; i++) {
      cin >> data;
      if (now + 1 == n) {
        next = 0;
        nextdata = s[0];
      } else {
        next = now + 1;
        nextdata = s[next];
      }

      sum1 = sum1 - nextdata + data;
      if (sum1 > max)
        max = sum1;
      now = next;
      s[now] = data;
    }

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

#include <iostream>

using namespace std;

int main() {

  int n, k;
  int a[100000];

  while (cin >> n >> k) {
    if (n == 0 && k == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int max = a[0];
    int t = 0;
    for (int i = 0; i < k; i++) {
      t += a[i];
    }
    if (t > max) {
      max = t;
    }
    for (int i = k; i < n; i++) {
      t += a[i];
      t -= a[i - k];
      if (t > max) {
        max = t;
      }
    }
    cout << max << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int n, k;
  int a[100000];

  while (cin >> n >> k) {
    if (n == 0 && k == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int max = a[0];
    for (int i = 0; i <= n - k; i++) {
      int t = 0;
      int l = 0;
      for (int j = i; j < n; j++) {
        l++;
        t += a[j];
        if (t > max) {
          max = t;
        }
        if (l == k) {
          break;
        }
      }
    }
    cout << max << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {

  int n, k, s, data;
  s = 0;

  while (cin >> n >> k, n && k) {
    vector<int> sum;

    rep(i, n) {
      cin >> data;
      sum.push_back(data);
    }

    data = 0;

    rep(i, k) { data += sum[i]; }

    int res;
    res = data;

    rep(i, n - k) {
      data -= sum[i];
      data += sum[i + k];
      res = max(res, data);
    }

    cout << res << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {

  int n, k, s, data;
  s = 0;

  while (cin >> n, n) {
    cin >> k;
    vector<int> sum;

    rep(i, n) {
      cin >> data;
      sum.push_back(data);
    }

    rep(i, k) {
      data = 0;
      rep(j, k) {
        if (i + j < n)
          data += sum[i + j];
      }
      if (s < data)
        s = data;
    }

    cout << s << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  int n, k;
  int a[100001];
  while (cin >> n >> k, n) {
    int ans = 0;
    rep(i, n) { cin >> a[i]; }
    rep(i, k) ans += a[i];
    int sum = 0;
    int tmp = ans;
    for (int i = k; i < n; i++) {
      sum = tmp;
      sum -= a[i - k];
      sum += a[i];
      ans = max(ans, sum);
      tmp = sum;
    }
    FIN(ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  int n, k;
  while (cin >> n >> k, n) {
    int a[n];
    int ans = 0;
    rep(i, n) {
      cin >> a[i];
      if (i >= k - 1) {
        int tmp = 0;
        rep(j, k) { tmp += a[i - j]; }
        ans = max(ans, tmp);
      }
    }
    FIN(ans);
  }

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

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int n, k, a, max;
  int set[100001];
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      break;
    max = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &set[i]);
    }
    for (int i = 0, sum = 0; i < n - k + 1; i++, sum = 0) {
      if (set[i - 1] < set[i + k - 1] || i == 0) {
        for (int j = i, l = i + k - 1;; j++, l--) {
          sum += set[j] + set[l];
          if (l - j == 1) {
            break;
          } else if (l == j) {
            sum -= set[j];
            break;
          }
        }
      }
      if (max < sum || i == 1) {
        max = sum;
      }
    }
    printf("%d\\n", max);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int n, k, a, max;
  int set[100001];
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      break;
    max = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &set[i]);
    }

    for (int i = 0, sum = 0; i < n - k + 1; i++, sum = 0) {
      for (int j = i, l = i + k - 1;; j++, l--) {
        sum += set[j] + set[l];
        if (l - j == 1) {
          break;
        } else if (l == j) {
          sum -= set[j];
          break;
        }
      }
      if (max < sum || i == 1) {
        max = sum;
      }
    }
    printf("%d\\n", max);
  }
}