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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265

int main(void) {
  int max = -1000000000;
  int n;
  int min, data;
  cin >> n;
  cin >> min;
  for (int i = 0; i < n - 1; i++) {
    cin >> data;
    if (data - min > max)
      max = data - min;
    if (min > data)
      min = data;
  }
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265

int main(void) {
  int max = -1000000000;
  int n;
  int *data;
  cin >> n;
  data = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (data[j] - data[i] > max)
        max = data[j] - data[i];
    }
  }
  cout << max << endl;
  delete[] data;
  return 0;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {

  int x[200000];
  int n, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  int max = -1000000000, min = x[0];
  for (j = 1; j < n; j++) {
    if (x[j] - min > max)
      max = x[j] - min;
    if (min > x[j])
      min = x[j];
  }
  printf("%d\\n", max);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n, R[200000], cost;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> R[i];
    if (i == 1)
      cost = R[i] - R[i - 1];
    if (i > 1) {
      for (int j = 0; j < i; j++) {
        if (cost < R[i] - R[j]) {
          cost = R[i] - R[j];
        }
      }
    }
  }

  cout << cost << endl;

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

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

int main(void) {
  int num;
  int input;
  int lst[200000];
  int small;
  int large;
  int maximum;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> lst[i];
  }
  maximum = -2000000000;
  small = lst[0];
  large = lst[0];

  for (int i = 1; i < num; i++) {
    maximum = max(maximum, lst[i] - small);
    small = min(small, lst[i]);
  }
  cout << maximum << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int num;
  int input;
  int lst[200000];
  int head;
  int tail;

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

  int between = lst[1] - lst[0];
  int max = lst[1] - lst[0];
  for (int i = 0; i < num; i++) {
    for (int j = i + 1; j < num; j++) {
      between = lst[j] - lst[i];
      if (between > max)
        max = between;
    }
  }

  cout << max << "\\n";
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[200000];
  int minid[200000];
  int total = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      continue;
    if (a[minid[i - 1]] > a[i]) {
      minid[i] = i;
    } else {
      minid[i] = minid[i - 1];
    }
    total = max(total, a[i] - a[minid[i - 1]]);
  }
  cout << total << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int count = 0;
  int a[200000];
  int buy = 100000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int sell = 0;
  int total = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      total = max(total, a[j] - a[i]);
    }
  }
  /*    for(int i=0;i<n;i++){
          cout << a[i][1] << a[i][0] << endl;
      }*/

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> R(n);
  rep(i, n) cin >> R[i];

  int maxV = -2000000000;
  int minV = R[0];
  for (int i = 1; i < n; ++i) {
    maxV = max(maxV, R[i] - minV);
    minV = min(minV, R[i]);
  }
  cout << maxV << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> R(n);
  rep(i, n) cin >> R[i];

  int ans = -mod;
  rep(i, n) {
    for (int j = i + 1; j < n; ++j) {
      ans = max(ans, R[j] - R[i]);
    }
  }
  cout << ans << endl;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int mn = INT_MAX;
  int ans = INT_MIN;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    ans = max(ans, t - mn);
    mn = min(t, mn);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int max;
  int cnt;
  int num[2000000] = {};
  cin >> cnt;
  for (int i = 0; i < cnt; i++) {
    cin >> num[i];
  }
  max = num[1] - num[0];
  for (int i = 0; i < cnt - 1; i++) {
    for (int j = i + 1; j < cnt; j++) {
      if ((num[j] - num[i]) > max) {
        max = num[j] - num[i];
      }
    }
  }
  cout << max << endl;
}
Problem p02258 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 2000000;

int main() {
  int R[MAX], n;

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

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 2000000000;

int main() {
  int R[MAX], n;

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

  int maxv = -20000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, max = -1000000000, min;
  cin >> n;
  cin >> min;
  int x;

  for (int i = 1; i < n; i++) {
    cin >> x;
    if ((x - min) > max)
      max = x - min;
    if (min > x)
      min = x;
  }

  cout << max << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, ans = -1000000000;
  cin >> n;
  int *p = new int[n];

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

  for (int i = n - 1; i > 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if ((p[i] - p[j]) > ans)
        ans = p[i] - p[j];
    }
  }
  cout << ans << "\\n";
  delete[] p;
  return 0;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define INT_MIN -2000000000
#define MAX_R 200001
using namespace std;

int main() {
  int n, k;
  while (cin >> n) {
    int max = INT_MIN;
    int r[MAX_R];
    k = n;
    while (k--) {
      cin >> r[k];
    }
    for (int i = 0; i < n; i++) {
      if (r[i] < max)
        continue;
      for (int j = i + 1; j < n; j++) {
        if (r[i] - r[j] > max)
          max = r[i] - r[j];
      }
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define INT_MIN -2000000000
#define MAX_R 200001
using namespace std;

int main() {
  int n, k;
  while (cin >> n) {
    int max = INT_MIN;
    int r[MAX_R];
    k = n;
    while (k--) {
      cin >> r[k];
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (r[i] - r[j] > max)
          max = r[i] - r[j];
      }
    }
    cout << max << endl;
  }
  return 0;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#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 <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> rs(n);
  for (auto &r : rs) {
    cin >> r;
  }

  int ans = INT_MIN;
  int min_r = rs[0];
  for (int i = 1; i < n; i++) {
    ans = max(ans, rs[i] - min_r);
    min_r = min(min_r, rs[i]);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#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 <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> rs(n);
  for (auto &r : rs) {
    cin >> r;
  }

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

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int main() {
  int n;
  cin >> n;
  vector<ll> r(n);
  loop(i, 0, n) { cin >> r[i]; }
  ll M = -1 * INF;
  ll m = r[0];
  loop(i, 1, n) {
    m = min(m, r[i - 1]);
    M = max(M, r[i] - m);
  }
  cout << M << "\\n";
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int main() {
  int n;
  cin >> n;
  vector<ll> r(n);
  loop(i, 0, n) { cin >> r[i]; }
  ll M = -1 * INF;
  ll m = r[0];
  loop(i, 0, n - 1) {
    if (r[i] == m) {
      vector<ll> r2(n);
      r2 = r;
      sort(r2.begin() + i + 1, r2.end());
      m = r2.back();
    }
    M = max(M, m - r[i]);
  }
  cout << M << "\\n";
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int size, max, sa;

  cin >> size;

  int *array = new int[size];

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

  max = -2000000000;

  int minv = array[0];

  for (int i = 1; i < size; i++) {
    if (max < array[i] - minv) {
      max = array[i] - minv;
    }
    if (minv > array[i]) {
      minv = array[i];
    }
  }

  cout << max << "\\n";

  delete[] array;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int size, max, sa;

  cin >> size;

  int *array = new int[size];

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

  max = array[size - 1] - array[0];

  for (int i = size - 1; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      sa = array[i] - array[j];
      if (max < sa) {
        max = sa;
      }
    }
  }

  cout << max << "\\n";

  delete[] array;
  return 0;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

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

  int maxValue = Rt[1] - Rt[0];
  int min = Rt[0];

  for (int i = 0; i < n; i++) {
    if (Rt[i] < min) {
      min = Rt[i];
    } else {
      if ((Rt[i] - min) > maxValue && i != 0) {
        maxValue = Rt[i] - min;
      }
    }
  }

  printf("%d\\n", maxValue);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

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

  int max = Rt[1] - Rt[0];
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < i; k++) {
      if (Rt[i] - Rt[k] > max) {
        max = Rt[i] - Rt[k];
      }
    }
  }
  printf("%d\\n", max);

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

#include <climits>
#include <iostream>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int r[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> r[t];
  }
  int max;
  int min;
  max = INT_MIN;
  min = r[0];
  for (int j = 1; j <= n - 1; j++) {
    max = std::max(max, r[j] - min);
    min = std::min(min, r[j]);
  }
  std::cout << max << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <climits>
#include <iostream>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int r[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> r[t];
  }
  int max;
  max = INT_MIN;
  for (int i = 0; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (max < r[j] - r[i]) {
        max = r[j] - r[i];
      }
    }
  }
  std::cout << max << std::endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, r[200010], max = -2e9, rmin = 2e9;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    if (r[i] < rmin) {
      rmin = r[i];
      for (int j = i + 1; j < n; j++) {
        if (r[j] - r[i] > max)
          max = r[j] - r[i];
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, r[200010], max = -2e9;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (r[j] - r[i] > max)
        max = r[j] - r[i];
    }
  }

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

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

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

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

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

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

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

#include <iostream>
using namespace std;
int a[200000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int min = a[0];
  int maxn = a[1] - a[0];
  for (int j = 1; j < n; j++) {
    if (a[j] - min > maxn)
      maxn = a[j] - min;
    if (a[j] < min)
      min = a[j];
  }
  cout << maxn << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[20000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maxn = a[1] - a[0];
  for (int j = 1; j <= n - 1; j++)
    for (int i = 0; i < j; i++) {
      if (a[j] - a[i] > maxn)
        maxn = a[j] - a[i];
    }
  cout << maxn << endl;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, a[1000000], x, y, mi, an;
int main() {
  cin >> n;
  for (x = 0; x < n; x++) {
    cin >> a[x];
    if (x == 1) {
      an = a[x] - a[x - 1];
    }
    if (x == 0) {
      mi = a[x];
    }
    if (an < a[x] - mi) {
      an = a[x] - mi;
    }
    if (mi > a[x]) {
      mi = a[x];
    }
  }
  cout << an << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, a[1000000], x, y, mi, an;
int main() {
  cin >> n;
  for (x = 0; x < n; x++) {
    cin >> a[x];
    for (y = x - 1; y >= 0; y--) {
      if (x == 1) {
        mi = a[x];
      }
      if (a[x] < mi) {
        mi = a[x];
      }
      if (x == 1 && y == 0) {
        an = a[x] - a[y];
      }
      if (an < a[x] - a[y]) {
        an = a[x] - a[y];
      }
    }
  }
  cout << an << endl;
}
Problem p02258 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int i = 0;
  int n = 0;
  int min;
  int now;
  int max_margin = -2147483648;
  int margin;

  scanf("%d", &n);
  scanf("%d", &min);
  for (i = 1; i < n; i++) {
    scanf("%d", &now);
    margin = now - min;
    if (margin > max_margin) {
      max_margin = margin;
    }
    if (now < min) {
      min = now;
    }
  }
  printf("%d\\n", max_margin);

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int i = 0;
  int n = 0;
  int min;
  int now;
  int max_margin = -2147483648;
  int margin;

  scanf("%d", &n);
  scanf("%d", &min);
  for (i = 1; i < n; i++) {
    scanf("%d", now);
    margin = now - min;
    if (margin > max_margin) {
      max_margin = margin;
    }
    if (now < min) {
      min = now;
    }
  }
  printf("%d\\n", max_margin);

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

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> R(n);
  rep(i, n) cin >> R[i];

  ll maxv = R[1] - R[0];
  ll minv = R[0];

  for (int j = 1; j < n; j++) {
    maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
    minv = minv < R[j] ? minv : R[j];
  }

  cout << maxv << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

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

  vector<ll> R(n);
  rep(i, n) cin >> R[i];

  ll ans = -1001001001001;

  rep(i, n) for (int j = i + 1; j < n; j++) ans =
      (R[j] - R[i] > ans ? R[j] - R[i] : ans);

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

#include <array>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  int len;
  cin >> len;
  array<int, 200000> nums;

  for (int i = 0; i < len; i++)
    cin >> nums[i];

  int mi = nums[0];
  int diffMax = numeric_limits<int>::min();
  for (int i = 1; i < len; i++) {
    diffMax = max<int>(diffMax, nums[i] - mi);
    mi = min<int>(mi, nums[i]);
  }

  cout << diffMax << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <array>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  int len;
  cin >> len;
  array<int, 200000> nums;

  for (int i = 0; i < len; i++)
    cin >> nums[i];

  int diffMax = numeric_limits<int>::min();
  for (int i = 0; i < len - 1; i++) {
    for (int j = i + 1; j < len; j++) {
      if (nums[j] - nums[i] > diffMax)
        diffMax = nums[j] - nums[i];
    }
  }

  cout << diffMax << endl;

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

#include <cstdlib>
#include <iostream>
#include <vector>
#define MIN -1000000000

void min(std::vector<int> R, int n) {
  int maxv = MIN;
  int minv = R[0];
  int dif;

  for (int j = 1; j < n; j++) {
    dif = R[j] - minv;
    if (dif > maxv) {
      maxv = dif;
    }
    if (R[j] < minv) {
      minv = R[j];
    }
  }
  std::cout << maxv << std::endl;
  return;
}

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> R(n);
  for (int i = 0; i < n; i++) {
    std::cin >> R[i];
  }
  min(R, n);
  return EXIT_SUCCESS;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <vector>

void max_dif(std::vector<int> R, int n);
std::vector<int> insertionSort(std::vector<int> A, int N, int th);
void print(std::vector<int> A, int N);

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> R(n);
  for (int i = 0; i < n; i++) {
    std::cin >> R[i];
  }
  max_dif(R, n);
  return EXIT_SUCCESS;
}

void max_dif(std::vector<int> R, int n) {
  std::vector<int> A(n, 0);
  int dif = R[1] - R[0];
  int temp;
  for (int i = 1; i < n; i++) {
    A = insertionSort(R, n, i);
    temp = A[n - 1] - A[i - 1];
    if (temp > dif) {
      dif = temp;
    }
  }
  std::cout << dif << std::endl;
  return;
}

std::vector<int> insertionSort(std::vector<int> A, int N, int th) {
  int v;
  int j;
  for (int i = th + 1; i <= N - 1; i++) {
    v = A[i];
    j = i - 1;
    while (j >= th && A[j] > v) {
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
  }
  return A;
}

void print(std::vector<int> A, int N) {
  for (int i = 0; i < N - 1; i++) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N - 1] << std::endl;
}
Problem p02258 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int rt[200000];

int main() {
  ios::sync_with_stdio(false);
  int n;
  int i, j;
  int max, min;
  cin >> n;
  max = 0x80000000;
  for (i = 0; i < n; i++) {
    cin >> rt[i];
  }
  min = rt[0];
  for (i = 1; i < n; i++) {
    if ((rt[i] - min) > max) {
      max = rt[i] - min;
    }
    if ((rt[i]) < min) {
      min = rt[i];
    }
  }
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int n, i, j, l, answer = 0;
  cin >> n;
  int A[n];
  for (int u = 0; u < n; u++) {
    cin >> l;
    A[u] = l;
  }
  answer = A[1] - A[0];
  for (int s = 2; s < n; s++) {
    i = A[s];
    for (int t = 0; t < s; t++) {
      j = A[t];
      if ((i - j) > answer) {
        answer = i - j;
      }
    }
  }
  cout << answer << endl;
  return 0;
}