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

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
// #define INF (1LL<<59)

struct edge {
  int to, cost;
};

#define MAX_V 100000
vector<edge> G[MAX_V];

void dijkstra(int s, vector<int> &d) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  rep(i, d.size()) d[i] = INF;
  d[s] = 0;
  que.push(pii(0, s));

  while (que.size()) {
    pii p = que.top();
    que.pop();

    int v = p.second;
    if (d[v] < p.first)
      continue;
    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > e.cost && d[v] <= e.cost) {
        d[e.to] = e.cost;
        que.push(pii(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].pb(edge{b, c});
  }

  vector<int> d(n);
  dijkstra(0, d);

  int ans = -1;

  rep(i, n) {
    for (auto &e : G[i]) {
      if (e.to == n - 1) {
        if (d[i] > e.cost)
          continue;
        ans = max(e.cost, ans);
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
// #define INF (1LL<<59)

struct edge {
  int to, cost;
};

#define MAX_V 100000
vector<edge> G[MAX_V];

void dijkstra(int s, vector<int> &d) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  rep(i, d.size()) d[i] = INF;
  d[s] = 0;
  que.push(pii(0, s));

  while (que.size()) {
    pii p = que.top();
    que.pop();

    int v = p.second;

    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > e.cost && d[v] <= e.cost) {
        d[e.to] = e.cost;
        que.push(pii(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].pb(edge{b, c});
  }

  vector<int> d(n);
  dijkstra(0, d);

  int ans = -1;

  rep(i, n) {
    for (auto &e : G[i]) {
      if (e.to == n - 1) {
        if (d[i] > e.cost)
          continue;
        ans = max(e.cost, ans);
      }
    }
  }

  cout << ans << endl;
}
Problem p01075 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100001
struct edge {
  int to, cost;
};
typedef pair<int, int> P;

int N, M;
int d[MAX_N];
vector<edge> G[MAX_N];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    G[a].push_back((edge){b, c});
  }

  int ans = -1;
  priority_queue<P, vector<P>, greater<P>> Q;

  fill(d, d + MAX_N, (1e9 + 1));
  Q.push(P(1, 1));
  d[1] = 1;

  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int pos = p.second;
    int cost = p.first;
    if (d[pos] < cost)
      continue;
    for (int i = 0; i < (int)G[pos].size(); i++) {
      edge e = G[pos][i];
      if (e.cost < d[pos])
        continue;
      if (e.to == N)
        ans = max(ans, e.cost);
      if (d[e.to] > e.cost) {
        d[e.to] = e.cost;
        Q.push(P(d[e.to], e.to));
      }
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100001
struct edge {
  int to, cost;
};
typedef pair<int, int> P;

int N, M;
int d[MAX_N];
vector<edge> G[MAX_N];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    G[a].push_back((edge){b, c});
  }

  int ans = -1;
  priority_queue<P, vector<P>, greater<P>> Q;

  fill(d, d + MAX_N, (1e9));
  Q.push(P(1, 1));
  d[1] = 1;
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int pos = p.second;
    int cost = p.first;
    if (d[pos] < cost)
      continue;
    for (int i = 0; i < (int)G[pos].size(); i++) {
      edge e = G[pos][i];
      if (e.cost < d[pos])
        continue;
      if (e.to == N)
        ans = max(ans, e.cost);
      if (d[e.to] > e.cost) {
        d[e.to] = e.cost;
        Q.push(P(d[e.to], e.to));
      }
    }
  }

  assert(ans < 1000000000 || N == 2);
  printf("%d\\n", ans);
  return 0;
}
Problem p01078 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10000

int main() {
  int n, k;
  double ans;

  cin >> n >> k;

  ans = 1 * 1 * sin(2 * M_PI / n) * n / 2;

  if (k > 1) {
    double a = sqrt(2 * (1 - cos(2 * M_PI / n)));
    ans -= (tan(M_PI / n * (k - 1)) * a / 2) * a / 2 * n;
  }

  printf("%.10lf\\n", ans);

  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10000

int main() {
  int n, k;
  double ans;

  cin >> n >> k;

  ans = 1 * 1 * sin(2 * M_PI / n) * n / 2;

  debug(ans);

  if (k > 1) {
    double a = sqrt(2 * (1 - cos(2 * M_PI / n)));
    debug(tan(M_PI / n) * a / 2);
    ans -= (tan(M_PI / n * (k - 1)) * a / 2) * a / 2 * n;
  }

  printf("%.10lf\\n", ans);

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
const double PI = 3.1415926535897932384626433832795028841971;
const int INF = 1000000007;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n;
bool saw[100000];
vector<int> d[100000];
vector<int> v[100000];

int dfs(int x) {
  int ret = 0;
  saw[x] = true;
  rep(i, v[x].size()) {
    if (saw[v[x][i]])
      continue;
    int z = dfs(v[x][i]);
    if (d[x].size() < 2)
      d[x].push_back(z);
    else {
      if (z > d[x][1])
        d[x][1] = z;
    }
    if (d[x].size() == 2 && d[x][0] < d[x][1])
      swap(d[x][0], d[x][1]);
    ret = max(ret, d[x][0]);
  }
  return ret + 1;
}

void dfs2(int x) {
  saw[x] = true;
  rep(i, v[x].size()) {
    if (!saw[v[x][i]])
      continue;
    int dep;
    if (d[x].size() != 0)
      dep = d[x][0];
    else
      dep = 0;
    if (1 + dep != d[v[x][i]][0]) {
      d[x].push_back(d[v[x][i]][0] + 1);
    } else {
      if (d[v[x][i]].size() == 1)
        d[x].push_back(1);
      else
        d[x].push_back(d[v[x][i]][1] + 1);
    }
  }
  sort(d[x].begin(), d[x].end(), greater<int>());
  rep(i, v[x].size()) {
    if (saw[v[x][i]])
      continue;
    dfs2(v[x][i]);
  }
}

int main() {
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0);
  rep(i, n) sort(d[i].begin(), d[i].end(), greater<int>());
  rep(i, n) saw[i] = false;
  dfs2(0);
  rep(i, n) printf("%d\\n", (n - 1) * 2 - d[i][0]);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
const double PI = 3.1415926535897932384626433832795028841971;
const int INF = 1000000007;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n;
bool saw[100000];
vector<int> d[100000];
vector<int> v[100000];

int dfs(int x) {
  int ret = 0;
  saw[x] = true;
  d[x].push_back(0);
  rep(i, v[x].size()) {
    if (saw[v[x][i]])
      continue;
    d[x].push_back(dfs(v[x][i]));
    ret = max(ret, d[x][d[x].size() - 1]);
  }
  return ret + 1;
}

void dfs2(int x, int dep) {
  saw[x] = true;
  rep(i, v[x].size()) {
    if (!saw[v[x][i]])
      continue;
    if (1 + d[x][0] != d[v[x][i]][0]) {
      d[x].push_back(d[v[x][i]][0] + 1);
    } else {
      if (d[v[x][i]].size() == 1)
        d[x].push_back(1);
      else
        d[x].push_back(d[v[x][i]][1] + 1);
    }
  }
  sort(d[x].begin(), d[x].end(), greater<int>());
  rep(i, v[x].size()) {
    if (saw[v[x][i]])
      continue;
    dfs2(v[x][i], dep + 1);
  }
}

int main() {
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0);
  rep(i, n) sort(d[i].begin(), d[i].end(), greater<int>());
  rep(i, n) saw[i] = false;
  dfs2(0, 0);
  rep(i, n) printf("%d\\n", (n - 1) * 2 - d[i][0]);
}
Problem p01081 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>

const int N = 1000000;

int n;
char string[N + 1];
std::deque<int> letters[26];

int count[N];
bool present[N];

void modify(int k, int v) {
  for (; k < n; k += ~k & k + 1) {
    count[k] += v;
  }
}

int query(int k) {
  int ret = 0;
  for (; k >= 0; k -= ~k & k + 1) {
    ret += count[k];
  }
  return ret;
}

void remove(int i) {
  present[i] = false;
  modify(i, -1);
}

int main() {
  scanf("%s", string);
  n = strlen(string);
  for (int i = 0; i < n; ++i) {
    letters[(int)(string[i] -= 'a')].push_back(i);
  }

  int odd_count = 0;
  for (int i = 0; i < 26; ++i) {
    odd_count += letters[i].size() & 1;
  }
  if (odd_count != (n & 1)) {
    puts("-1");
    return 0;
  }
  memset(present, true, sizeof(present));
  for (int i = 0; i < n; ++i) {
    modify(i, 1);
  }
  long long answer = 0;
  for (int l = 0, r = n - 1; l < r;) {
    if (!present[l]) {
      l++;
    } else if (!present[r]) {
      r--;
    } else {
      int left_cost = query(n - 1) - query(letters[(int)string[l]].back());
      int right_cost = query(letters[(int)string[r]].front()) - 1;
      answer += std::min(left_cost, right_cost);
      int token = left_cost < right_cost ? string[l] : string[r];
      remove(letters[token].front());
      remove(letters[token].back());
      letters[token].pop_front();
      letters[token].pop_back();
    }
  }
  std::cout << answer << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>

const int N = 200000;

int n;
char string[N + 1];
std::deque<int> letters[26];

int count[N];
bool present[N];

void modify(int k, int v) {
  for (; k < n; k += ~k & k + 1) {
    count[k] += v;
  }
}

int query(int k) {
  int ret = 0;
  for (; k >= 0; k -= ~k & k + 1) {
    ret += count[k];
  }
  return ret;
}

void remove(int i) {
  present[i] = false;
  modify(i, -1);
}

int main() {
  scanf("%s", string);
  n = strlen(string);
  for (int i = 0; i < n; ++i) {
    letters[(int)(string[i] -= 'a')].push_back(i);
  }

  int odd_count = 0;
  for (int i = 0; i < 26; ++i) {
    odd_count += letters[i].size() & 1;
  }
  if (odd_count != (n & 1)) {
    puts("-1");
    return 0;
  }
  memset(present, true, sizeof(present));
  for (int i = 0; i < n; ++i) {
    modify(i, 1);
  }
  long long answer = 0;
  for (int l = 0, r = n - 1; l < r;) {
    if (!present[l]) {
      l++;
    } else if (!present[r]) {
      r--;
    } else {
      int left_cost = query(n - 1) - query(letters[(int)string[l]].back());
      int right_cost = query(letters[(int)string[r]].front()) - 1;
      answer += std::min(left_cost, right_cost);
      int token = left_cost < right_cost ? string[l] : string[r];
      remove(letters[token].front());
      remove(letters[token].back());
      letters[token].pop_front();
      letters[token].pop_back();
    }
  }
  std::cout << answer << std::endl;
  return 0;
}
Problem p01085 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

int main(void) {
  long m, min, max, p[10000], g[10000], kkk, rrr;

  for (long o = 0; o < 10000; o++) {
    cin >> m >> min >> max;

    if (m == 0 && min == 0) {
      if (max == 0) {
        break;
      }
    }

    kkk = 0;

    for (long i = 1; i < m + 1; i++) {
      cin >> p[i];
    }

    for (long j = min; j < max + 1; j++) {
      g[j] = p[j] - p[j + 1];

      if (kkk <= g[j]) {
        kkk = 0;
        kkk = g[j];
        rrr = 0;
        rrr = j;
      }
    }

    cout << rrr << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

int main(void) {
  int m, min, max, p[100], g[100], kkk, rrr;

  for (int o = 0; o < 100; o++) {
    cin >> m >> min >> max;

    if (m == 0 && min == 0) {
      if (max == 0) {
        break;
      }
    }

    kkk = 0;

    for (int i = 1; i < m + 1; i++) {
      cin >> p[i];
    }

    for (int j = min; j < max + 1; j++) {
      g[j] = p[j] - p[j + 1];

      if (kkk <= g[j]) {
        kkk = 0;
        kkk = g[j];
        rrr = 0;
        rrr = j;
      }
    }

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

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;

    if (m == 0 && nmin == 0 && nmax == 0)
      break;

    int P[200];
    for (int i = 0; i < m; i++) {
      cin >> P[i];
    }

    int gap = -1;
    int n = -1;

    for (int i = nmin; i <= nmax; i++) {
      int g = P[i - 1] - P[i];

      if (gap <= g) {
        gap = g;
        n = i;
      }
    }
    cout << n << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;

    if (m == 0 && &nmin == 0 && nmax == 0)
      break;

    int P[200];
    for (int i = 0; i < m; i++) {
      cin >> P[i];
    }

    int gap = -1;
    int n = -1;

    for (int i = nmin; i < nmax; i++) {
      int g = P[i - 1] - P[i];

      if (gap <= g) {
        gap = g;
        n = i;
      }
    }
    cout << n << endl;
  }
  return 0;
}
Problem p01085 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  int m, nmin, nmax;
  while (1) {
    cin >> m >> nmin >> nmax;
    if (m == 0 && nmin == 0 && nmax == 0) {
      return 0;
    }
    int pi, pib, sa, ans;
    int samax = 0;
    for (int i = 0; i < m; i++) {
      if (i > 0)
        pib = pi;
      cin >> pi;
      if (i == 0)
        pib = pi;
      if (nmin <= i && i <= nmax) {
        sa = pib - pi;
        if (sa >= samax) {
          samax = sa;
          ans = i;
        }
      }
      //   if(i>nmax)break;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  int m, nmin, nmax;
  while (1) {
    cin >> m >> nmin >> nmax;
    if (m == 0 && nmin == 0 && nmax == 0) {
      return 0;
    }
    int pi, pib, sa, ans;
    int samax = 0;
    for (int i = 0; i < m; i++) {
      if (i > 0)
        pib = pi;
      cin >> pi;
      if (i == 0)
        pib = pi;
      if (nmin <= i && i <= nmax) {
        sa = pib - pi;
        if (sa >= samax) {
          samax = sa;
          ans = i;
        }
      }
      if (i > nmax)
        break;
    }
    cout << ans << endl;
  }
}
Problem p01085 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  while (1) {
    int m, nmin, nmax, p[201], maxg = 0, n;
    scanf("%d %d %d", &m, &nmin, &nmax);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &p[i]);
    }
    for (int j = nmin; j <= nmax; j++) {
      if (p[j] - p[j + 1] >= maxg) {
        maxg = p[j] - p[j + 1];
        n = j;
      }
    }
    if (m == 0 && nmin == 0 && nmax == 0) {
      return 0;
    } else {
      printf("%d\\n", n);
    }
  }
}


Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  while (1) {
    int m, nmin, nmax, p[201], maxg = 0, n;
    scanf("%d %d %d", &m, &nmin, &nmax);
    for (int i = 1; i < m; i++) {
      scanf("%d", &p[i]);
    }
    for (int j = nmin; j <= nmax; j++) {
      if (p[j] - p[j + 1] >= maxg) {
        maxg = p[j] - p[j + 1];
        n = j;
      }
    }
    if (m == 0 && nmin == 0 && nmax == 0) {
      return 0;
    } else {
      printf("%d\\n", n);
    }
  }
}
Problem p01085 (C++) — buggy submission, verdict: Runtime Error

// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#define ll long long
#define all(a) (a).begin(), (a).end()

int main(int argc, char const *argv[]) {
  while (1) {
    int m = 0, nmin = 0, nmax = 0;
    scanf("%d%d%d", &m, &nmin, &nmax);
    if (m == 0 && nmin == 0 && nmax == 0) {
      break;
    }
    std::vector<int> p(m + 1);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &p[i]);
    }
    int temp = 0, memo = 0, memoid = 0;
    for (int i = nmin; i <= nmax; i++) {
      temp = p[i] - p[i + 1];
      memo = std::max(memo, temp);
      if (memo == temp)
        memoid = i;
    }
    p.erase(all(p));
    printf("%d\\n", memoid);
  }
  return 0;
}

Error: 0

Fixed submission:

// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#define ll long long
#define all(a) (a).begin(), (a).end()

int main(int argc, char const *argv[]) {
  while (1) {
    int m = 0, nmin = 0, nmax = 0;
    scanf("%d%d%d", &m, &nmin, &nmax);
    if (m == 0 && nmin == 0 && nmax == 0) {
      break;
    }
    std::vector<int> p(m);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &p[i]);
    }
    int temp = 0, memo = 0, memoid = 0;
    for (int i = nmin; i <= nmax; i++) {
      temp = p[i] - p[i + 1];
      memo = std::max(memo, temp);
      if (memo == temp)
        memoid = i;
    }
    p.erase(all(p));
    printf("%d\\n", memoid);
  }
  return 0;
}
Problem p01085 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using VI = vector<long>;

int main() {
  int m, nmin, nmax;
  while (1) {
    cin >> m >> nmin >> nmax;
    if (m) {
      VI ps;
      for (int i = 0; i < m; i++) {
        long p;
        cin >> p;
        ps.push_back(p);
      }
      long n;
      long maxgap = 0;
      for (int i = nmin; i <= nmax; i++) {
        assert(i - 1 >= 0);
        assert(i < m);
        long gap = ps[i - 1] - ps[i];
        if (gap >= maxgap) {
          maxgap = gap;
          n = i;
        }
      }
      cout << n << endl;
    } else {
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

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

using VI = vector<long>;

int main() {
  int m, nmin, nmax;
  while (1) {
    cin >> m >> nmin >> nmax;
    if (m) {
      VI ps;
      for (int i = 0; i < m; i++) {
        long p;
        cin >> p;
        ps.push_back(p);
      }
      long n;
      long maxgap = 0;
      for (int i = nmin; i <= nmax; i++) {
        long gap = ps[i - 1] - ps[i];
        if (gap >= maxgap) {
          maxgap = gap;
          n = i;
        }
      }
      assert(maxgap != 0);
      cout << n << endl;
    }
  }
}
Problem p01085 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;
    if (m == 0 && nmin == 0 && nmax == 0)
      break;

    int gap = -1;
    int n = -1;
    int P[200];
    for (int i = 0; i < m; i++) {
      cin >> P[i];
    }
    for (int i = nmin; i < nmax + 1; i++) {
      if (P[i - 1] - P[i] >= gap) {
        gap = P[i - 1] - P[i];
        n = i;
      }
    }
    cout << n << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;
    if (m = 0)
      break;
    int gap = 0;
    int n = 0;
    int P[m];
    for (int i = 0; i < m; i++) {
      cin >> P[i];
    }
    for (int i = nmin - 1; i < nmax - 1; i++) {
      if (P[i] - P[i + 1] >= gap) {
        gap = P[i] - P[i + 1];
        n = i;
      }
    }
    cout << n << endl;
  }
  return 0;
}
Problem p01085 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int m, n_min, n_max, gap = 1000000, z;
  int ary[1000001];

  while (1) {
    cin >> m >> n_min >> n_max;
    if (m == 0 && n_min == 0 && n_max == 0)
      break;

    for (int i = 1; i <= m; i++) {
      cin >> ary[i];
    }

    for (int i = n_min; i <= n_max; i++) {
      if (gap >= ary[i + 1] - ary[i]) {
        gap = ary[i + 1] - ary[i];
        z = i;
      }
    }
    cout << z << endl;
    gap = 1000000;
    z = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int m, n_min, n_max, gap = 1000000, z;
  int ary[1000001];

  cin >> m >> n_min >> n_max;
  while (1) {
    if (m == 0 && n_min == 0 && n_max == 0)
      break;

    int j = 0;
    while (m--) {
      cin >> ary[j];
      j++;
    }

    for (int i = n_min; i < n_max; i++) {
      if (gap >= ary[i - 1] - ary[i]) {
        gap = ary[i - 1] - ary[i];
        z = i;
      }
    }
    cout << z;
  }

  return 0;
}