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

#include <iostream>
using namespace std;

int a, b, n;
struct cross {
  bool isbuilding;
  int access;
};
cross map[100][100];

void read() {
  cin >> n;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      map[i][j].isbuilding = false;
      map[i][j].access = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    map[x][y].isbuilding = true;
  }
  map[0][0].access = 1;
  return;
}

void dp_a(int crossa, int crossb) {
  if (crossa + 1 == a) {
    return;
  }
  if (map[crossa + 1][crossb].isbuilding) {
    return;
  }
  map[crossa + 1][crossb].access += map[crossa][crossb].access;
  return;
}

void dp_b(int crossa, int crossb) {
  if (crossb + 1 == b) {
    return;
  }
  if (map[crossa][crossb + 1].isbuilding) {
    return;
  }
  map[crossa][crossb + 1].access += map[crossa][crossb].access;
  return;
}

void solve() {
  for (int i = 0; i < a + b - 2; i++) {
    int times;
    if (i < (a < b) ? a : b) {
      times = i + 1;
    } else if (i <= (a > b) ? a : b) {
      times = (a < b) ? a : b;
    } else {
      times = a + b - i - 1;
    }

    for (int j = 0; j < times; j++) {
      dp_a(j, i - j);
      dp_b(j, i - j);
    }
  }
  return;
}

int main() {
  while (1) {
    cin >> a >> b;
    if (!a && !b) {
      break;
    }
    read();
    solve();
    cout << map[a - 1][b - 1].access << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int a, b, n;
struct cross {
  bool isbuilding;
  int access;
};
cross map[16][16];

void read() {
  cin >> n;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      map[i][j].isbuilding = false;
      map[i][j].access = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    map[x][y].isbuilding = true;
  }
  map[0][0].access = 1;
  return;
}

void dp_a(int crossa, int crossb) {
  if (crossa + 1 == a) {
    return;
  }
  if (map[crossa + 1][crossb].isbuilding) {
    return;
  }
  map[crossa + 1][crossb].access += map[crossa][crossb].access;
  return;
}

void dp_b(int crossa, int crossb) {
  if (crossb + 1 == b) {
    return;
  }
  if (map[crossa][crossb + 1].isbuilding) {
    return;
  }
  map[crossa][crossb + 1].access += map[crossa][crossb].access;
  return;
}

void solve() {
  for (int i = 0; i < a + b - 2; i++) {
    int times;
    if (i < (a < b) ? a : b) {
      times = i + 1;
    } else if (i <= (a > b) ? a : b) {
      times = (a < b) ? a : b;
    } else {
      times = a + b - i - 1;
    }

    for (int j = 0; j < times; j++) {
      dp_a(j, i - j);
      dp_b(j, i - j);
    }
  }
  return;
}

int main() {
  while (1) {
    cin >> a >> b;
    if (!a && !b) {
      break;
    }
    read();
    solve();
    cout << map[a - 1][b - 1].access << endl;
  }
  return 0;
}
Problem p00438 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FIELD_SIZE 17

using namespace std;

int main() {
  int w, h;

  while (cin >> w >> h, w || h) {
    int n, o[40][40];
    int dp[FIELD_SIZE][FIELD_SIZE] = {0};

    // 障害物の初期化
    REP(i, 40) REP(j, 40) o[i][j] = 1;

    cin >> n;

    REP(i, n) {
      int x, y;
      cin >> x >> y;
      o[x][y] = 0;
    }

    // 縦横の縁は必ず1通り(障害物を除く)
    dp[1][1] = 1;

    // 障害物が無ければ上と左のマスを足していく
    // ※上下反転してます
    for (int y = 1; y <= h; y++) {
      for (int x = 0; x < w; x++) {
        if (y == 1 && x == 0)
          continue; // 最初の座標は無視
        if (o[x + 1][y])
          dp[x + 1][y] = dp[x][y] + dp[x + 1][y - 1];
      }
    }

    // REP(i, h+1) {
    //     REP(j, w+1) {
    //         if ( i == h && j == w ) cout << "'" << dp[j][i] << "'";
    //         else cout << dp[j][i] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    cout << dp[w][h] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

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

using namespace std;

/*

dp[50][16][16] (50は余分に取ってある)

dp[ステップ数][x][y] = この地点で起こりうる全通り

*/

// #define MAX_STEP 50
#define FIELD_SIZE 17

int main() {
  int w, h;

  while (cin >> w >> h, w || h) {
    int n, o[40][40];
    int dp[FIELD_SIZE][FIELD_SIZE] = {0};

    // 障害物の初期化
    REP(i, 40) REP(j, 40) o[i][j] = 1;

    cin >> n;

    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      // cout << y << " " << x << endl;
      o[x][y] = 0;
    }

    // 縦横の縁は必ず1通りしか無い
    REP(x, FIELD_SIZE) dp[1][x] = 1;
    REP(y, FIELD_SIZE) dp[y][1] = 1;

    for (int y = 2; y <= h + 1; y++) {
      for (int x = 2; x <= w + 1; x++) {
        if (o[y][x])
          dp[y][x] = dp[y - 1][x] + dp[y][x - 1];
      }
    }

    // REP(i, h+2) {
    //     REP(j, w+2) {
    //         if ( i == h && j == w ) cout << "'" << dp[j][i] << "'";
    //         else cout << dp[j][i] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    cout << dp[w][h] << endl;
  }

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

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

int main() {
  int a, b; // a:N-S b:E-W
  std::cin >> a >> b;

  while (a != 0 || b != 0) {
    int n; // n:work place
    std::cin >> n;
    std::vector<std::vector<int>> work;
    work.resize(b);

    int buf_x, buf_y;
    for (int i = 0; i < n; ++i) {
      std::cin >> buf_x >> buf_y;
      work.at(buf_y - 1).push_back(buf_x - 1);
    }

    std::vector<int> way;
    way.resize(a);
    way[0] = 1;
    for (int i = 0; i < b; ++i) {
      for (int j = 0; j < a; ++j) {
        if (std::find(work[i].begin(), work[i].end(), j) == work[i].end()) {
          if (j != 0)
            way[j] += way[j - 1];
        } else {
          way[j] = 0;
        }
      }
    }

    std::cout << way[a - 1] << std::endl;

    std::cin >> a >> b;
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int a, b; // a:N-S b:E-W
  std::cin >> a >> b;

  while (a != 0 || b != 0) {
    int n; // n:work place
    std::cin >> n;
    std::vector<std::vector<int>> work;
    work.resize(b);

    int buf_x, buf_y;
    for (int i = 0; i < n; ++i) {
      std::cin >> buf_x >> buf_y;
      work.at(buf_y - 1).push_back(buf_x - 1);
    }

    for_each(work.begin(), work.end(),
             [](std::vector<int> x) { std::sort(x.begin(), x.end()); });

    std::vector<int> way;
    way.resize(a);
    way[0] = 1;
    for (int i = 0; i < b; ++i) {
      if (work[i][0] == 0)
        way[0] = 0;

      for (int j = 1; j < a; ++j) {
        if (std::find(work[i].begin(), work[i].end(), j) == work[i].end()) {
          way[j] += way[j - 1];
        } else {
          way[j] = 0;
        }
      }
    }

    std::cout << way[a - 1] << std::endl;

    std::cin >> a >> b;
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

const double PI = 3.14159265358979323846;

int map[16][16];
int w, h;

int f(int x, int y) {
  if ((map[x][y] == -1) || (x < 0) || (y < 0) || (w <= x) || (h <= y)) {
    return 0;
  }
  if ((x == 0) && (y == 0)) {
    return 1;
  }

  if (map[x][y] != 0) {
    return map[x][y];
  }
  return f(x - 1, y) + f(x, y - 1);
}

int main() {
  while (true) {
    int n;
    cin >> w >> h >> n;
    if ((w == 0) && (h == 0))
      return 0;
    for (int i = 0; i < w; ++i) {
      for (int j = 0; j < h; ++j) {
        map[i][j] = 0;
      }
    }
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      map[x - 1][y - 1] = -1;
    }

    cout << f(w - 1, h - 1) << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

const double PI = 3.14159265358979323846;

int map[1001][1001];
int w, h;

int f(int x, int y) {
  if ((map[x][y] == -1) || (x < 0) || (y < 0) || (w <= x) || (h <= y)) {
    return 0;
  }
  if ((x == 0) && (y == 0)) {
    return 1;
  }

  if (map[x][y] != 0) {
    return map[x][y];
  }
  return f(x - 1, y) + f(x, y - 1);
}

int main() {
  while (true) {
    int n;
    cin >> w >> h >> n;
    if ((w == 0) && (h == 0))
      return 0;
    for (int i = 0; i < w; ++i) {
      for (int j = 0; j < h; ++j) {
        map[i][j] = 0;
      }
    }
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      map[x - 1][y - 1] = -1;
    }

    cout << f(w - 1, h - 1) << endl;
  }
}
Problem p00438 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  while (1) {
    int machi[20][20] = {0, 0}, a, b, n;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      break;
    }
    cin >> n;
    a--;
    b--;
    // if (n == 0) { break; }//cout << n << endl;
    bool kouji[20][20] = {false};
    for (int i = 0; i < n; i++) {
      int d, e;
      cin >> d >> e;
      kouji[d - 1][e - 1] = true;
    }
    machi[0][0] = 1;
    REP(i, a + 1) {
      if (kouji[i][0] == false) {
        machi[i][0] = 1;
      } else {
        //			cout << i<<"a";
        break;
      }
    }

    REP(i, b + 1) {
      if (kouji[0][i] == false) {
        machi[0][i] = 1;
      } else {
        break;
      }
    }
    FOR(i, 1, a + 1) {
      FOR(j, 1, b + 1) {
        if (kouji[i][j] != true) {
          machi[i][j] = machi[i - 1][j] + machi[i][j - 1];
          //	cout << i << " " << j << " " << machi[i][j] << endl;
        }
      }
    }
    cout << machi[a][b] << endl;
  }

  //	cout << "s";
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int machi[20][20] = {0, 0}, a, b, n;
  bool kouji[20][20] = {false};
  a--;
  b--;
  while (scanf("%d", &n)) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      break;
    }
    // if (n == 0) { break; }//cout << n << endl;
    for (int i = 0; i < n; i++) {
      int d, e;
      cin >> d >> e;
      kouji[d - 1][e - 1] = true;
    }
    machi[0][0] = 1;
    REP(i, a + 1) {
      if (kouji[i][0]) {
        machi[i][0] = 1;
      } else {
        break;
      }
    }

    REP(i, b + 1) {
      if (kouji[0][i]) {
        machi[0][i] = 1;
      } else {
        break;
      }
    }
    FOR(i, 1, a + 1) {
      FOR(j, 1, b + 1) {
        if (kouji[i][j] != true) {
          machi[i][j] = machi[i - 1][j] + machi[i][j - 1];
          // cout << i << " " << j << " " << machi[i][j] << endl;
        }
      }
    }
    cout << machi[a][b] << endl;
  }

  //	cout << "s";
  return 0;
}
Problem p00438 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int road[100][100];
int mem[100][100];
int a, b;
int n;
int solve(int x, int y);
int main() {
  int x, y;
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      break;
    }
    road[a - 1][b - 1] = 2;
    cin >> n;
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        road[i][j] = 0;
        mem[i][j] = 0;
      }
    }

    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      road[x - 1][y - 1] = 1;
    }

    int ans;
    ans = solve(0, 0);

    cout << ans << endl;
  }
  return 0;
}

int solve(int x, int y) {
  if (road[x][y] == 1)
    return 0;
  if (x >= a || y >= b)
    return 0;
  if (mem[x][y] > 0)
    return mem[x][y];
  if (x == a - 1 && y == b - 1)
    return 1;
  return mem[x][y] = solve(x + 1, y) + solve(x, y + 1);
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int road[17][17];
int mem[17][17];
int a, b;
int n;
int solve(int x, int y);
int main() {
  int x, y;
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      break;
    }
    road[a - 1][b - 1] = 2;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        road[i][j] = 0;
        mem[i][j] = 0;
      }
    }

    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      road[x - 1][y - 1] = 1;
    }

    int ans;
    ans = solve(0, 0);

    cout << ans << endl;
  }
  return 0;
}

int solve(int x, int y) {
  if (road[x][y] == 1)
    return 0;
  if (x >= a || y >= b)
    return 0;
  if (mem[x][y] > 0)
    return mem[x][y];
  if (x == a - 1 && y == b - 1)
    return 1;
  return mem[x][y] = solve(x + 1, y) + solve(x, y + 1);
}
Problem p00438 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int i, j, h, w, n, x, y;

  while (cin >> w >> h, h != 0, w != 0) {
    int r[21][21] = {0};
    r[1][1] = 1;

    cin >> n;

    for (i = 0; i < n; i++) {
      cin >> x >> y;
      r[y][x] = -1;
    }
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (r[i][j] != -1) {
          if (i != 1 && r[i - 1][j] != -1) {
            r[i][j] += r[i - 1][j];
          }
          if (j != 1 && r[i][j - 1] != -1) {
            r[i][j] += r[i][j - 1];
          }
        }
      }
    }

    /*   for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
        //	cout<<"# "<<r[i][j];
        printf("| %3d ",r[i][j]);
      }
      cout<<endl;
    }
    */
    cout << r[h][w] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int i, n, m, j;
  double h;
  int a[1000001];
  int s[1000001];

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

    j = 1;
    h = n / 2;
    for (j = 0; j < n; j++) {
      s[a[j]]++;
      if (h < s[a[j]]) {
        cout << a[j] << endl;
        j = 0;
        break;
      }
    }
    if (j)
      cout << "NO COLOR" << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int cnt, n, m, dat[110000];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> dat[i];
    }
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      ans += dat[i];
    }
    cnt = ans;
    for (int i = m; i < n; i++) {
      cnt += dat[i] - dat[i - m];
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

int n = 0;
int k = 0;
int a[100020] = {0};
int table[100020] = {0};

bool input() {
  cin >> n >> k;
  if (!n && !k)
    return false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    table[i + 1] = a[i] + table[i];
  }
  return true;
}

int solve() {
  int Max = -1001001001;
  for (int i = 0; i < n - k; i++) {
    Max = max(Max, table[i + k] - table[i]);
  }
  return Max;
}

int main() {
  while (input()) {
    printf("%d\\n", solve());
  }
  return 0;
}


Error: 0

Fixed submission:

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

typedef long long ll;

int n = 0;
int k = 0;
ll sum[100020] = {0};

ll solve() {
  ll ans = -1001001001001;
  for (int i = 0; i < n; i++) {
    if (!i)
      ans = max(ans, sum[k - 1]);
    else
      ans = max(ans, sum[i + k - 1] - sum[i - 1]);
  }
  return ans;
}

int main() {
  while (1) {
    cin >> n >> k;
    if (!n && !k)
      break;
    for (int i = 0; i < n; i++) {
      int cmp = 0;
      cin >> cmp;
      if (i == 0)
        sum[0] = cmp;
      else
        sum[i] = sum[i - 1] + cmp;
    }
    printf("%lld\\n", solve());
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(int argc, char **argv) {
  int *a, *a2, m, n, t1, t2;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }

    a = (int *)calloc(n - m + 1, sizeof(int));
    a2 = (int *)calloc(n, sizeof(int));

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

    for (int i = 0; i < m; i++) {
      a[0] += a2[i];
    }

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

    sort(a, a + (n - m + 1));

    cout << a[n - m] << endl;

    free(a2);
    free(a);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main(int argc, char **argv) {
  int *a, *a2, m, n, t1, t2;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }

    a = (int *)calloc(n - m + 1, sizeof(int));
    a2 = (int *)calloc(n, sizeof(int));

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

    for (int i = 0; i <= (n - m); i++) {
      for (int j = i; j < (m + i); j++) {
        a[i] += a2[j];
      }
    }
    sort(a, a + (n - m + 1));

    cout << a[n - m] << endl;

    free(a2);
    free(a);
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#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;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

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

    vector<int> a;
    int sum = 0;
    int m;
    rep(i, k) {
      cin >> s;
      a.push_back(s);
      sum += a[i];
    }

    m = sum;

    REP(i, k, n - 1) {
      cin >> s;
      a.push_back(s);
      sum += a[i] - a[i - k];
      if (m <= sum)
        m = sum;
    }

    cout << m << endl;

    a.clear();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#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;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

  int n, k, s;
  vector<int> a;

  while (true) {

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

    rep(i, n) {
      cin >> s;
      a.push_back(s);
    }

    int m = 0;
    int sum = 0;
    REP(j, 0, n - k) {
      REP(i, j, k + j - 1)
      sum += a[i];

      if (m <= sum)
        m = sum;
      sum = 0;
    }

    cout << m << endl;

    a.clear();
  }

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

#include <cstdio>
using namespace std;
int main() {
  int n, k;
  int s = 0;
  int a[100000] = {0};
  for (;;) {
    scanf("%d%d", &n, &k);
    if (n == 0 && k == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int x = 0;
    for (int i = 0; i < k; i++) {
      x += a[i];
    }
    s = x;
    for (int i = 0; i < (n - k); i++) {
      x -= a[i];
      x += a[i + k];
      if (s < x)
        s = x;
    }
    printf("%d\\n", s);
  }
  return 0;
}

Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

int sum(int S[], int begin, int end) {
  int ans = 0;
  for (int i = begin; i < end; ++i) {
    ans += S[i];
  }
  return ans;
}

int main() {

  int n, k;
  for (;;) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    int dummy = sum(S, 0, k);
    int m = n - k + 1;
    int tmp = 0;
    int ans = dummy;
    for (int i = 1; i < m; ++i) {
      int tmp = dummy - S[i - 1] + S[i + k - 1];
      dummy = tmp;
      if (ans < tmp)
        ans = tmp;
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int sum(int S[], int begin, int end) {
  int ans = 0;
  for (int i = begin; i < end; ++i) {
    ans += S[i];
  }
  return ans;
}

int main() {

  int n, k;
  for (;;) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    int m = n - k + 1;
    int tmp = 0;
    int ans = -1000000000;
    for (int i = 0; i < m; ++i) {
      int tmp = sum(S, i, i + k);
      if (ans < tmp)
        ans = tmp;
    }

    cout << ans << endl;
  }

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

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

int main() {
  int n, k;

  while (true) {
    int max = 0, s = 0;
    vector<int> a;

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

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

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

    max = s;

    for (int i = 1; i <= n - k; i++) {
      int t = i + k - 1;
      s = s - a[i - 1] + a[t];
      if (max < s)
        max = s;
    }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef priority_queue<int> PQ;

int main() {
  int n, k;

  while (true) {
    int max = 0;
    vector<int> a;

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

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

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

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