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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main() {
  int n, k;

  while (cin >> n >> k, n + k) {
    int ans = -50000;
    int sum = 0;
    vi series;
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      series.push_back(m);

      if (i < k - 1)
        sum += m;
      else {
        sum += m - series[i - k];
        ans = max(ans, sum);
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  int input[100000];
  int sun;
  while (cin >> n >> k, n || k) {
    int ans = 0;
    for (int i = 0; i < n; i++)
      cin >> input[i];

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

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

int main() {
  while (1) {
    int n, k, b[100100] = {}, sum = 0, sum1 = 0, ans = 0, j = 0;
    cin >> n >> k;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (i < k) {
        sum += b[i];
      } else {
        ans = max(ans, sum);
        sum = sum - b[j] + b[i];
        j++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n, k, b[100100] = {}, sum[100100] = {};

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    int n, k, x = 0, ma = 0, p = 0, q = 0;
    cin >> n >> k;
    q = k - 1;
    if (n == 0 && k == 0)
      break;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < k; i++) {
      x += a[i];
    }
    ma = max(ma, x);
    for (int i = 0; i < n - k; i++) {
      q++;
      x += a[q];
      x -= a[p];
      p++;
      ma = max(ma, x);
    }
    cout << ma << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    int N, M;
    int lis[100002];
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++)
      cin >> lis[i];
    int now = 0, ans = 0;
    for (int i = 0; i < M; i++)
      now += lis[i], ans += lis[i];
    for (int i = 1; i + M <= N; i++)
      now = now - lis[i - 1] + lis[i + M - 1], ans = max(now, ans);
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    int N, M;
    int lis[20000];
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++)
      cin >> lis[i];
    int now = 0, ans = 0;
    for (int i = 0; i < M; i++)
      now += lis[i], ans += lis[i];
    for (int i = 1; i + M <= N; i++)
      now = now - lis[i - 1] + lis[i + M - 1], ans = max(now, ans);
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, k;
  int a[100100];
  int b[100100];
  for (;;) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k;
  int a[100100];
  for (;;) {
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int n, k, l;
  int N[100001], ans, sum, tmp;
  while (cin >> n >> k, n && k) {
    ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> N[i];
    }

    for (l = 0; l < k; l++) {
      sum += N[l];
    }
    ans = max(ans, sum);
    tmp = sum;
    for (int i = l; i < n; i++) {
      tmp = sum;
      sum += N[i];
      sum -= N[i - k];
      tmp = sum;
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int n, k;
  int N[100001], ans, sum;
  while (cin >> n >> k, n && k) {
    ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> N[i];
    }
    for (int i = 0; i < n - k; i++) {
      sum = accumulate(N + i, N + i + k, 0);
      /*for(int j = i ; j < k + i ; j++){
        sum += N[j];
        }*/
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

#define rep(i, a) for (int i = 0; i < (a); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

typedef vector<int> vi;

int main() {
  int n, k;
  while (cin >> n >> k, n || k) {
    vi nums(n);
    int sum = 0;
    rep(i, k) {
      cin >> nums[i];
      sum += nums[i];
    }
    int ans = sum;
    repi(i, k, n) {
      cin >> nums[i];
      sum -= nums[i - k];
      sum += nums[i];
      if (sum > ans) {
        ans = sum;
      }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

/**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@16:55

 **********************************************/
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  while (1) {

    int n = 0;
    int k = 0;
    int total = 0, answer = 0;
    int data[5000];

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

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

    for (int j = 0; j < n - k + 1; j++) {

      if (j == 0) {
        for (int i = 0; i < k; i++) {
          total = total + data[j + i];
        }
        // cout << "subtotal1="<<total<<endl;
      } else {

        total = total - data[j - 1] + data[j + k - 1];
        // cout << "subtotal2="<<total<<endl;
      }
      // cout << "answer="<<answer<<"subtotal="<<total<<endl;
      if (total > answer) {
        answer = total;
      }
      // cout << "answer="<<answer<<endl;
    }

    cout << answer << endl;
  }

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

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

using namespace std;

int main() {
  vector<int> results;

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

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

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

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

    results.push_back(max);
  }

  for (int i = 0; i < results.size(); i++)
    cout << results[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  vector<int> results;

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

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

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

      if (max < s)
        max = s;
    }

    results.push_back(max);
  }

  for (int i = 0; i < results.size(); i++)
    cout << results[i] << endl;

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

#include <iostream>

using namespace std;

int main() {

  int in, k;

  while (cin >> in >> k) {
    if (in == 0 && k == 0)
      break;
    int data[in];
    int sum;

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

    int tmp = 0;

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

    for (int i = k; i < in; i++) {
      tmp -= data[num];
      num++;
      tmp += data[i];
      if (i == 0 || sum < tmp)
        sum = tmp;
    }

    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int in, k;

  while (cin >> in >> k) {
    if (in == 0 && k == 0)
      break;
    int data[in];
    int sum;

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

    for (int i = 0; i <= in - k; i++) {
      int tmp = 0;
      for (int j = i; j < i + k; j++) {
        tmp += data[j];
      }
      if (i == 0 || sum < tmp)
        sum = tmp;
    }

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

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

int main() {
  int n, k, x;
  vector<int> s;
  int start, end, ans = 0, sum;

  while (1) {

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

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

    start = 0;
    end = k;
    sum = 0;
    for (int i = start; i < end; i++) {
      sum += s[i];
    }
    ans = max(ans, sum);

    while (end < n) {
      sum += s[end];
      sum -= s[start];
      ans = max(ans, sum);

      start++;
      end++;
    }

    printf("%d\\n", ans);
    ans = 0;
    sum = 0;
    s.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k, x;
  vector<int> s;
  int start, end, ans = 0, sum;

  while (1) {

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

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

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

      start++;
      end++;
    }

    printf("%d\\n", ans);
    ans = 0;
    s.clear();
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
        ++n;
        if(noww>w || nowh>h) return 0;
        if(noww==w && nowh==h) return 1;
        int ret=0;
        n=0;
        if(n)
        ret+=dfs(w,h,++noww,nowh,n,b);
        ret+=dfs(w,h,noww,++nowh,n,b);
        ret+=dfs(w,h,++noww,nowh,n,b);
        ret+=dfs(w,h,noww,++nowh,n,b);
        return ret;
}

int main()u{
        int w,h;
        cin >> w >> h;
        cout << dfs(w,h,1,1,2,0) << endl;
        return 0;
}
*/

int main() {
  int n, k;
  while (cin >> n >> k && n != 0 && k != 0) {
    int maxi = 0, pre = 0;
    vector<int> seq(n);
    for (int i = 0; i < n; ++i) {
      cin >> seq[i];
    }
    for (int i = 0; i < k; ++i) {
      maxi += seq[i];
      pre += seq[i];
    }
    for (int i = 1; i < n - k + 1; ++i) {
      pre = pre - seq[i - 1] + seq[i + k - 1];
      maxi = max(maxi, pre);
    }
    cout << maxi << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
        ++n;
        if(noww>w || nowh>h) return 0;
        if(noww==w && nowh==h) return 1;
        int ret=0;
        n=0;
        if(n)
        ret+=dfs(w,h,++noww,nowh,n,b);
        ret+=dfs(w,h,noww,++nowh,n,b);
        ret+=dfs(w,h,++noww,nowh,n,b);
        ret+=dfs(w,h,noww,++nowh,n,b);
        return ret;
}

int main()u{
        int w,h;
        cin >> w >> h;
        cout << dfs(w,h,1,1,2,0) << endl;
        return 0;
}
*/

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, k, a[100000] = {};
  long long int sum = -10000000, tmp;
  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 + k < n; i++) {
      tmp = 0;
      for (int j = 0; j < k; j++) {
        tmp += a[i + j];
      }
      if (sum < tmp)
        sum = tmp;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
long long m[100000][2];
int main() {
  while (1) {
    long long n, k, i, j, x = 0;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (i = 0; i < n; i++)
      cin >> m[i][0];
    m[0][1] = m[0][0];
    for (i = 1; i < n; i++) {
      m[i][1] = m[i - 1][1] + m[i][0];
    }
    x = m[k - 1][1];
    for (i = k; i < n; i++) {
      x = max(x, m[i][1] - m[i - k][1]);
    }
    cout << x << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int a[100000][5] = {0};
int b[100000];
int Y(int l, int j, int m) {
  long long s = 0;
  int u;
  if (m - j >= l) {
    for (u = j; u < j + l && u < m; u++) {
      s += b[u];
    }
  }
  return s;
}
int main() {
  while (1) {
    int n, k, i, p = 0, o = 0;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> b[i];
    }
    a[0][p] = Y(k, o, n);
    for (i = 1; i < n; i++) {
      a[i][p] = max(a[i - 1][p], Y(k, i, n));
    }
    cout << a[n - 1][p] << endl;
    p++;
  }
  return 0;
}
Problem p00439 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iostream>

std::int64_t a[100000];

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

    std::int64_t res = 0, mem = 0;
    for (int i = 0; i < n; ++i) {
      mem += a[i];

      if (i >= k) {
        mem -= a[i - k];
        res = std::max(res, mem);
      }
    }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <fstream>

std::int64_t a[100000];

int main() {
  std::ifstream ifs("input.txt");
  std::ofstream ofs("output.txt");

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

    std::int64_t res = 0, mem = 0;
    for (int i = 0; i < n; ++i) {
      mem += a[i];

      if (i >= k)
        mem -= a[i - k];

      res = std::max(res, mem);
    }

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

#include <cstdio>
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int main() {
  const int MAX_N = 100000;
  int n, a[MAX_N], k, S, S1, S2;
  int p;

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

    S = 0;
    for (p = 0; p < k; p++) {
      S += a[p];
    }
    S1 = S;

    while (p < n) {
      S2 = S1 + a[p] - a[p - k];

      S = max(S, S2);

      S1 = S2;

      p++;
    }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int main() {
  const int MAX_N = 100000;
  int n, a[MAX_N], k, S, S1, S2;
  int p;

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

    S = 0;
    for (p = 0; p < k; p++) {
      S += a[p];
    }
    S1 = S;

    while (p < n) {
      S2 = S1 + a[p] + a[p - k];

      S = max(S, S2);

      S1 = S2;
    }

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

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int s = 0;
    int m = 0;

    while (s + k - 1 < n) {
      int cm = 0;
      for (int j = 0; j < k; j++) {
        cm += a[s + j];
      }
      if (cm > m) {
        m = cm;
      }
      s++;
    }
    cout << m << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int s = 0;
    int m = 0;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, result = -100000;
  int num[100005] = {0};
  int memo[100000] = {0};
  while (cin >> n >> m, n + m) {
    for (int i = 0; i < n; i++)
      cin >> num[i];
    for (int i = m - 1; i < n; i++) {
      memo[i] = 0;
      if (i == m - 1) {
        for (int j = 0; j < m; j++) {
          memo[i] += num[i - j];
        }
      } else if (i > m - 1) {
        memo[i] = memo[i - 1] + num[i] - num[i - m];
      }
    }
    for (int i = m - 1; i < n; i++) {
      result = max(result, memo[i]);
    }
    cout << result << endl;
    result = -100005;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, result;
  int num[100005];
  int memo[100000];
  while (1) {
    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; i++) {
      for (int j = 0; j < m; j++) {
        memo[i] = num[m - j];
      }
    }
    for (int i = 0; i < n; i++) {
      result = max(result, memo[i]);
    }
    cout << result << endl;
  }
  return 0;
}