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

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

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

    if (n == 0 && k == 0) {
      break;
    }

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

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

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }

    int number[n], sum[n - k + 1];
    for (int i = 0; i < n; i++) {
      cin >> number[i];
    }
    for (int i = 0; i < n - k; i++) {
      sum[i] = 0;
      for (int j = 0; j < k; j++) {
        sum[i] += number[i + j];
      }
    }

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

    cout << ans << endl;
  }

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  int ans;
  while (true) {
    int a[100001] = {}, b[100001] = {};
    n = 0;
    k = 0;
    ans = 0;
    cin >> n >> k;
    if (n == 0 || k == 0)
      break;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int x = 0; x < k; x++) {
      b[1] += a[x + 1];
    }
    ans = b[1];
    for (int i = 2; i <= n; i++) {
      if ((i + k) == (n + 1))
        break;
      b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
      ans = max(b[i], ans);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (true) {
    int n, k;
    double a[100001] = {}, b[100001] = {}, ans;
    cin >> n >> k;
    if (n == 0 || k == 0)
      break;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      for (int x = 0; x < k; x++) {
        if (a[i + k - 1] == 0)
          break;
        b[i] += a[i + x];
      }
      if (b[i] > b[i - 1]) {
        ans = b[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    if (n == 0 && k == 0)
      break;
    int s[n], ans = 0, su = 0;
    for (int i = 0; i < n; i++)
      cin >> s[i];
    for (int i = 0; i < k; i++)
      su += s[i];
    ans = su;
    for (int i = k; i < n; i++) {
      su += (s[i] - s[i - k]);
      if (ans < su)
        ans = su;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define INF -10000000
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int s[n];
    long int ans = INF;
    for (int i = 0; i < n; i++)
      cin >> s[i];
    for (int i = m - 1; i < n; i++) {
      int su = 0;
      for (int j = i - m + 1; j <= i; j++)
        su += s[j];
      if (ans < su)
        ans = su;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

const int MAX_N = 1 << 18, INF = 1 << 24;

class SegmentTree {
public:
  SegmentTree(int _n) {
    n = 1;
    while (n < _n)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; i++) {
      data[i] = 0;
    }
  }

  void add(int k, int a) {
    k += n - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = data[k * 2 + 1] + data[k * 2 + 2];
    }
  }

  int calculate(int a, int b) { return _calculate(a, b, 0, 0, n); }

private:
  int data[MAX_N];
  int n;
  int _calculate(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return 0;

    if (a <= l && r <= b)
      return data[k];
    else {
      int l_child = _calculate(a, b, 2 * k + 1, l, (l + r) / 2),
          r_child = _calculate(a, b, 2 * k + 2, (l + r) / 2, r);
      return l_child + r_child;
    }
  }
};

int main() {
  int n, k;
  while (std::cin >> n >> k, n) {
    SegmentTree st(n);
    for (int i = 0; i < n; i++) {
      int a_i;
      std::cin >> a_i;
      st.add(i, a_i);
    }

    int res = -INF;

    for (int i = 0; i + k - 1 < n; i++) {
      res = std::max(res, st.calculate(i, i + k));
    }

    std::cout << res << std::endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>

const int MAX_N = 1 << 17, INF = 1 << 24;

class SegmentTree {
public:
  SegmentTree(int _n) {
    n = 1;
    while (n < _n)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; i++) {
      data[i] = 0;
    }
  }

  void add(int k, int a) {
    k += n - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = data[k * 2 + 1] + data[k * 2 + 2];
    }
  }

  int calculate(int a, int b) { return _calculate(a, b, 0, 0, n); }

private:
  int data[MAX_N];
  int n;
  int _calculate(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return 0;

    if (a <= l && r <= b)
      return data[k];
    else {
      int l_child = _calculate(a, b, 2 * k + 1, l, (l + r) / 2),
          r_child = _calculate(a, b, 2 * k + 2, (l + r) / 2, r);
      return l_child + r_child;
    }
  }
};

int main() {
  int n, k;
  while (std::cin >> n >> k, n) {
    SegmentTree st(n);
    for (int i = 0; i < n; i++) {
      int a_i;
      std::cin >> a_i;
      st.add(i, a_i);
    }

    int res = -INF;

    for (int i = 0; i + k - 1 < n; i++) {
      res = std::max(res, st.calculate(i, i + k));
    }

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

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

int main() {
  int n, k, max, temp, num, total;
  while (true) { // ベクターに格納
    cin >> n >> k;
    if (n == k != 0)
      break;
    vector<double> v;
    total = 0;
    v.push_back(total);
    for (int i = 0; i < n; i++) {
      cin >> num; // 入力をnumに代入
      total += num;
      v.push_back(total); // ベクターvにプッシュ
    }

    max = 0;
    temp = 0;
    for (int i = 0; i + k <= n; i++) {
      temp = v[i + k] - v[i];
      if (temp > max)
        max = temp; // tempが最も大きい数値ならmaxを更新
      temp = 0;     // tempの初帰化
    }
    cout << max << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n, k, max, temp, num;
  while (true) { // ベクターに格納
    cin >> n >> k;
    if (n == k != 0)
      break;
    vector<double> v;
    for (int i = 0; i < n; i++) {
      cin >> num;       // 入力をnumに代入
      v.push_back(num); // ベクターvにプッシュ
    }

    max = 0;
    temp = 0;
    for (int i = 0; (i + k) <= n; i++) {
      for (int j = 0; j < k; j++) {
        temp += v[i + j]; // tempにvのiからi+k番目までの総和を代入
      }
      // cout<<temp<<endl;
      if (temp > max)
        max = temp; // tempが最も大きい数値ならmaxを更新
      temp = 0;     // tempの初帰化
    }
    cout << max << endl;
  }
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, k;
  for (; cin >> n >> k, n;) {
    int d[n];
    for (int i = 0; i < n; i++)
      cin >> d[i];
    int sum = 0;
    int i;
    for (i = 0; i < k; i++) {
      sum += d[i];
    }
    int max = sum;
    for (; i < n; i++) {
      sum += d[i];
      sum -= d[i - k];
      if (max < sum)
        max = sum;
    }

    cout << max << endl;
  }
}

Error: TLE

Fixed submission:

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

#include <stdio.h>
int P[100001];

int main() {

  int n, k;
  int x, x1, x2, x3;
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      break;
    int s = 0, max = 0;

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

    for (int j = 0; j < k; j++)
      s += P[j];
    max = s;

    for (int i = k; i < n; i++) {
      s += P[i];
      s -= P[i - k];

      if (s > max)
        max = s;
    }

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

Error: TLE

Fixed submission:

#include <stdio.h>
int P[100001];

int main() {

  int n, k;
  int x, x1, x2, x3;
  while (1) {
    scanf("%d %d", &n, &k);
    if (n == 0 && k == 0)
      break;
    int s = 0, max = 0;

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

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

      if (s > max)
        max = s;
      s = 0;
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  int n, k, s, b;
  while (1) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    int m[100001] = {0};
    int a[100001];

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

    m[0] = 0;
    for (int i = 0; i < n; i++)
      m[i + 1] = m[i] + a[i];

    s = 0;

    for (int i = 1; i + k <= n; i++) {
      b = m[i + k] - m[i];
      if (s < b)
        s = b;
    }
    cout << s << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

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

    m[0] = a[0];
    for (int i = 0; i < n; i++)
      m[i + 1] = m[i] + a[i];

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

#include <iostream>
using namespace std;

int main() {
  int n, k, max, buf, *a;

  while (1) {
    cin >> n >> k;

    if (n || k) {
      max = buf = 0;

      a = new int[n];

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

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

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

      cout << max << endl;
    } else {
      break;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k, max, buf, *a;

  while (1) {
    cin >> n >> k;

    if (n || k) {
      max = 0;

      a = new int[n];

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

      for (int i = 0; i <= n - k; i++) {
        buf = 0;

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

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

      cout << max << endl;
    } else {
      break;
    }
  }

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

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  for (;;) {
    int n, k;
    int sum = 0, ans = 0;
    int a[100010] = {0};
    cin >> n;
    cin >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < k; i++) {
      sum += a[i];
    }
    ans = sum;
    for (int i = k; i < n; i++) {
      sum += a[i];
      sum -= a[i - k];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  for (;;) {
    int n, k;
    int sum = 0, sum2 = 0;
    int a[100010] = {0};
    cin >> n;
    cin >> 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++) {
      sum = 0;
      for (int j = 0; j < k; j++) {
        sum += a[j + i];
      }
      if (sum2 < sum)
        sum2 = sum;
    }
    cout << sum2 << endl;
  }

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

#include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void) {
  int n, k;
  int data[100000] = {0};

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

    for (int i = 0; i < n - 1; i++) {
      data[i + 1] += data[i];
    }
    for (int i = 0; i < n; i++) {
      //			printf("%2d ", data[i]);
    }
    int max = 0;
    for (int i = 0; i <= (n - k); i++) {
      if (!(i == 0))
        max = MAX(max, data[i + k - 1] - data[i - 1]);
      else
        max = data[i + k - 1];
    }
    //		printf("\\n");
    /*
    int max = 0, tmp;
    for (int i = 0; i <= (n - k); i++){
            tmp = 0;
            for (int j = i; j < (i + k); j++){
                    tmp += data[j];
            }
            max = MAX(max, tmp);
    }*/

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

  return (0);
}

Error: TLE

Fixed submission:

#include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void) {
  int n, k;
  int data[100000] = {0};

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

    for (int i = 0; i < n - 1; i++) {
      data[i + 1] += data[i];
    }
    int max = 0;
    for (int i = 0; i <= (n - k); i++) {
      int tmp = data[i + k] - data[i];
      for (int j = i; j < (i + k); j++) {
        if (data[j] < 0)
          tmp += data[j];
      }
      max = MAX(max, tmp);
    }

    /*
    int max = 0, tmp;
    for (int i = 0; i <= (n - k); i++){
            tmp = 0;
            for (int j = i; j < (i + k); j++){
                    tmp += data[j];
            }
            max = MAX(max, tmp);
    }*/

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  while (1) {
    int ans = 0, n, k, box[100005] = {0}, sum = 0;
    ;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < k; i++) {
      cin >> box[i];
      sum += box[i];
    }
    ans = sum;
    for (int i = k; i < n; i++) {
      cin >> box[i];
      sum += box[i] - box[i - k];
      if (sum > ans)
        ans = sum;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

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

using namespace std;

int n, k, s, ans, term, ans_t;
vector<int> a_n;
int m, t;

int main() {

  while (1) {
    m = 0;
    ans_t = 0;

    cin >> n >> k;

    if (n == 0 && k == 0) {
      break;
    }

    for (int q = 0; q < n; ++q) {
      cin >> term;
      a_n.push_back(term);
    }

    for (int q = 0; q < n; ++q) {
      if (q < k) {
        ans_t += a_n[q];
        ans = ans_t;
      } else {
        m = ans_t + a_n[q] - a_n[q - k];
        if (m > ans) {
          ans = m;
        }
        ans_t = m;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int n, k, s, ans, term, ans_t;
vector<int> a_n;
int m, t;

int main() {

  while (1) {
    m = 0;
    cin >> n >> k;

    if (n == 0 && k == 0) {
      break;
    }

    for (int q = 0; q < n; ++q) {
      cin >> term;
      a_n.push_back(term);
    }

    for (int q = 0; q < n + 1 - k; ++q) {
      s = q;
      ans_t = 0;

      for (; s < k + q; ++s) {
        ans_t += a_n[s];
      }

      if (q == 0) {
        ans = ans_t;
      } else {
        if (ans_t > ans) {
          ans = ans_t;
        }
      }
    }
    cout << ans << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int n, k;
  while (1) {
    int a[100000];
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    int max = 0, sum;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      sum = 0;
      if (i + k - 1 < n) {
        for (int j = 0; j < k; j++) {
          sum += a[i + j];
        }
        if (max < sum) {
          max = sum;
        }
      } else
        break;
    }
    cout << max << endl;
  }
}

Error: TLE

Fixed submission:

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

#include <iostream>
#define INF -10000000000000000;
using namespace std;

long long int num[100100];

int main() {
  long long int n, m;
  long long int sum = 0;
  long long int ans = INF;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 100100; i++) {
      num[i] = 0;
      if (num[i + 1] == 0)
        break;
    }
    for (int i = 0; i < n; i++) {
      cin >> num[i];
      if (i < m)
        sum += num[i];
    }
    //  cout<<sum<<endl;
    for (int i = 1; i < n - m; i++) {
      sum = sum - num[i - 1] + num[i + m - 1];
      //  cout<<sum<<endl;
      if (ans < sum)
        ans = sum;
    }
    cout << ans << endl;
    ans = INF;
    sum = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#include <iostream>
#include <vector>

using namespace std;

int suretu[100000];
int cont = 0;
int max_sum = 0;

int ret_maxsum(int n, int k, int wa, bool isBegin) {
  /*
  int temp = 0;
  int max = 0, cont = 0;
  int wa;
  //ツ陳シツ前ツづ個禿アツづつづ個計ツ算ツづ系ツ古つづ個計ツ算ツづ個和

  for(int i = 0; i < n-k+1; i++){
          for(int j = 0; j < k; j++){
                  temp += suretu[cont+j];
                  if(
                  printf("suretu%d = %d\\n",j,suretu[cont+j]);
          }
          cout << "**" << endl;
          if(temp > max){
                  printf("*maxツ更ツ新\\n");
                  max = temp;
          }
          temp = 0;
          cont++;
  }

  return max;
  */

  int temp = 0;
  int i;

  if (isBegin == 1) {
    for (i = 0; i < k; i++) {
      temp += suretu[cont + i];
    }
  } else {
    temp += wa + suretu[cont + k - 1];
  }
  wa = temp - suretu[cont];
  //	printf("temp = %d\\nwa = %d\\n\\n",temp,wa);
  cont++;

  if (max_sum < temp) {
    //		cout << "maxツ更ツ新:" << temp << endl;
    max_sum = temp;
  }

  if (cont == n - k + 1) {
    return max_sum;
  } else {
    return ret_maxsum(n, k, wa, 0);
  }
}

int main() {
  for (;;) {
    int n, k;

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

    printf("%d\\n", ret_maxsum(n, k, 0, 1));
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int suretu[100000];

int ret_maxsum(int n, int k) {
  int temp = 0;
  int max = 0, cont = 0;

  for (int i = 0; i < n - k + 1; i++) {
    for (int j = 0; j < k; j++) {
      temp += suretu[cont + j];
      //			printf("suretu%d = %d\\n",j,suretu[cont+j]);
    }
    //		cout << "**" << endl;
    if (temp > max) {
      //			printf("*maxツ更ツ新\\n");
      max = temp;
    }
    temp = 0;
    cont++;
  }

  return max;
}

int main() {
  for (;;) {
    int n, k;

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

    cout << ret_maxsum(n, k) << endl;
  }
}
Problem p00440 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

void solve() {
  int n, k;
  while (cin >> n >> k, n || k) {
    bool isBlank = false;
    vector<int> card(k);
    for (int i = 0; i < k; ++i) {
      cin >> card[i];
      if (card[i] == 0) {
        isBlank = true;
      }
    }
    sort(card.begin(), card.end());
    int pos = 1;
    if (card[0] == 0) {
      ++pos;
    }
    bool isUsed;
    int ans = 0;
    for (int i = pos; i < k; ++i) {
      if (isBlank) {
        isUsed = false;
      } else {
        isUsed = true;
      }
      int count = 1;
      int pre = card[i - 1];
      for (int j = i; j < k; ++j) {
        if (pre == card[j] - 1) {
          ++count;
          ans = max(ans, count);
          pre = card[j];
        } else {
          if (isUsed) {
            count = 0;
            break;
          } else {
            isUsed = true;
            ++count;
            ans = max(ans, count);
            pre = card[j] - 1;
            --j;
          }
        }
      }
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

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

using namespace std;

void solve() {
  int n, k;
  while (cin >> n >> k, n || k) {
    bool isBlank = false;
    vector<int> card(k);
    for (int i = 0; i < k; ++i) {
      cin >> card[i];
      if (card[i] == 0) {
        isBlank = true;
      }
    }
    sort(card.begin(), card.end());
    int pos = 1;
    if (card[0] == 0) {
      ++pos;
    }
    bool isUsed;
    int ans = 0;
    for (int i = pos; i < k; ++i) {
      if (isBlank) {
        isUsed = false;
      } else {
        isUsed = true;
      }
      int count = 1;
      int pre = card[i - 1];
      for (int j = i; j < k; ++j) {
        // cout << pre << " " << card[j] << " " << count << endl;
        if (pre == card[j] - 1) {
          ++count;
          ans = max(ans, count);
          pre = card[j];
        } else {
          if (isUsed) {
            count = 0;
          } else {
            isUsed = true;
            ++count;
            ans = max(ans, count);
            pre = card[j] - 1;
            --j;
          }
        }
        // cout << pre << " " << card[j] << " " << count << endl;
      }
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return (0);
}