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

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  int n;
  long long sum = 0, min, max, a;

  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (i == 0) {
      max = a;
      min = a;
    }
    if (max < a) {
      max = a;
    } else if (min > a) {
      min = a;
    }
    sum = sum + a;
  }
  cout << min << " " << max << " " << sum << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int main(void) {
  int n, min = 0, max = 0, a;
  long long sum = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; ++n) {
    scanf("%d", &a);
    if (max < a) {
      max = a;
    } else if (min > a) {
      min = a;
    }
    sum = sum + a;
  }
  printf("%d %d %d", min, max, sum);
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[10000];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  cout << a[0] << " " << a[n - 1] << " " << sum << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  int a, c = 0;
  cin >> a;
  int e[1000];
  for (int i = 0; i < a; i++) {
    cin >> e[i];
    c = c + e[i];
  }
  sort(e, e + a);
  cout << e[0] << " " << e[a - 1] << " " << c << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int A[10000];

int min(int n) {
  if (n == 1)
    return A[0];
  int t = min(n - 1);
  return A[n - 1] > t ? t : A[n - 1];
}

int max(int n) {
  if (n == 1)
    return A[0];
  int t = max(n - 1);
  return A[n - 1] > t ? A[n - 1] : t;
}

long long sum(int n) {
  if (n == 1)
    return A[0];

  return A[n - 1] + sum(n - 1);
}

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

  cout << min(n) << " " << max(n) << " " << sum(n) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int A[10000];

int min(int n) {
  if (n == 1)
    return A[0];
  return A[n - 1] > min(n - 1) ? min(n - 1) : A[n - 1];
}

int max(int n) {
  if (n == 1)
    return A[0];
  return A[n - 1] > max(n - 1) ? A[n - 1] : max(n - 1);
}

long long sum(int n) {
  if (n == 1)
    return A[0];

  return A[n - 1] + sum(n - 1);
}

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

  cout << min(n) << " " << max(n) << " " << sum(n) << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  long int n, a[10000], i, min = 0, max = 0, sum;

  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }

  sum = a[0];

  for (i = 1; i < n; i++) {
    if (a[min] > a[i]) {
      min = i;
    }
    if (a[max] < a[i]) {
      max = i;
    }
    sum = sum + a[i];
  }
  printf("%ld %ld %ld\\n", a[min], a[max], sum);

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, a[10000], i, min = 0, max = 0, sum;

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

  sum = a[0];

  for (i = 1; i < n; i++) {
    if (a[min] > a[i]) {
      min = i;
    }
    if (a[max] < a[i]) {
      max = i;
    }
    sum = sum + a[i];
  }
  printf("%d %d %d\\n", a[min], a[max], sum);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long sum_array(int v[], int a, int b) {
  long long tmp = 0;
  for (int i = a; i <= b; i++) {
    tmp += v[i];
  }
  return tmp;
}

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

  sort(a, a + n);

  int min = a[0];
  int max = a[n - 1];
  long long sum = sum_array(a, 0, n - 1);

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int MAX_N = 100;
int a[MAX_N];

int min_array(int v[], int a, int b) {
  int tmp = v[a];
  for (int i = a + 1; i <= b; i++) {
    if (v[i] < tmp)
      tmp = v[i];
  }
  return tmp;
}

int max_array(int v[], int a, int b) {
  int tmp = v[a];
  for (int i = a + 1; i <= b; i++) {
    if (v[i] > tmp)
      tmp = v[i];
  }
  return tmp;
}

int sum_array(int v[], int a, int b) {
  int tmp = 0;
  for (int i = a; i <= b; i++) {
    tmp += v[i];
  }
  return tmp;
}

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

  int min = min_array(a, 1, n);
  int max = max_array(a, 1, n);
  int sum = sum_array(a, 1, n);

  printf("%d %d %d\\n", min, max, sum);
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[100000];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[i];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, max, min;
  long long sum = 0;
  int a[10001];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, max, min;
  long long sum = 0;
  int a[1000];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, max, min;
  long long sum = 0;
  int a[10001];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[i];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int maxnum = 100000;
int n; // the number of number
int Array[maxnum];
int main() {
  cin >> n;
  int y_max;
  int y_min;
  long y_sum;
  for (int i = 0; i < n; i++) {
    cin >> Array[i];
  }
  y_max = Array[0];
  y_min = Array[0];
  y_sum = 0;
  for (int y = 0; y < n; y++) {
    if (y_min < Array[y]) {
      y_min = y_min;
    } else
      y_min = Array[y];
  }
  for (int z = 0; z < n; z++) {
    if (y_max > Array[z]) {
      y_max = y_max;
    } else
      y_max = Array[z];
  }
  for (int m = 0; m < n; m++) {
    y_sum = y_sum + Array[m];
  }
  cout << y_min << ' ' << y_max << ' ' << y_sum << endl;
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;
const int maxint = 1000000;
const int minint = -1000000;
const int maxnum = 100000;

int n; // the number of number
int Array[maxnum];
int main() {

  cin >> n;
  if (n > 10000 || n <= 0) {
    cout << "the input data is over the limit" << endl;
    return 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> Array[i];
    if (Array[i] < -1000000 || Array[i] > 1000000) {
      cout << "the input data is over the limit" << endl;
      return 1;
    }
  }
  int y_max = Array[0];
  int y_min = Array[0];
  long y_sum = 0;
  for (int y = 0; y < n; y++) {
    if (y_min < Array[y]) {
      y_min = y_min;
    } else
      y_min = Array[y];
  }
  for (int z = 0; z < n; z++) {
    if (y_max > Array[z]) {
      y_max = y_max;
    } else
      y_max = Array[z];
  }
  for (int m = 0; m < n; m++) {
    y_sum = y_sum + Array[m];
  }
  cout << y_min << ' ' << y_max << ' ' << y_sum;
  return 1;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int i;
  int num;
  int *data;

  scanf("%d", &num);

  data = new int[num];
  for (i = 0; i < num; i++)
    scanf("%d", &data[i]);

  int min, max;
  long long int sum = 0;
  min = max = data[0];
  for (i = 0; i < num; i++) {
    if (min > data[i])
      min = data[i];
    else if (max < data[i])
      max = data[i];
    sum += (long long int)data[i];
  }

  printf("%d %d %lld\\n", min, max, sum);

  delete[] data;
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int i;
  int a[10000];
  int n;
  int cnt;

  char c[2000000000];

  scanf("%d", &n);
  scanf("%s", c);

  cnt = 0;

  a[cnt] = 0;

  for (i = 0; i < 2000000000 && c[i] != '\\n'; i++) {
    if (c[i] == ' ') {
      cnt++;
      a[cnt] = 0;
    } else {
      c[i] = c[i] & 0x000F;
      if (a[cnt])
        a[cnt] *= 10;
      a[cnt] += c[i];
    }
  }

  int maxn, minn;
  maxn = minn = 0;
  cnt = 0;
  for (i = 0; i < n; i++) {
    cnt += a[i];

    if (a[i] > a[maxn])
      maxn = i;
    else if (a[i] < a[minn])
      minn = i;
  }

  printf("%d %d %d\\n", a[minn], a[maxn], cnt);
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a[10000] = {0}, i, k, small, max;
  long long gou;
  gou = 0;
  scanf("%d", &i);
  for (k = 0; k < i; k++) {
    scanf("%d", &a[k]);
  }
  small = a[0];
  max = a[0];

  for (k = 0; k < i; k++) {

    if (small > a[k]) {
      small = a[k];
    }

    if (max < a[k]) {
      max = a[k];
    }

    gou += a[k];
  }

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

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int a[10000] = {0}, i, k, max, small, gou;
  scanf("%d", &i);
  for (k = 0; k <= i; k++) {
    scanf("%d", a[k]);
  }
  max = a[0];
  small = a[0];
  for (k = 0; k <= i; k++) {

    if (max < a[k]) {
      max = a[k];
    }

    if (small > a[k]) {
      small = a[k];
    }
    gou += a[k];
  }

  printf("%d %d %d\\n", small, max, gou);
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int n, a[10001] = {0}; // 10001回
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int min = 1000000, max = -1000000, sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < min) {
      min = a[i];
    }
    if (a[i] > max) {
      max = a[i];
    }
    sum = sum + a[i];
  }
  cout << min << " " << max << " " << sum << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n, a[1001] = {0}; // 10001回
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long min = 1000000, max = -1000000, sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
    }
    if (a[i] > max) {
      max = a[i];
    }
    sum = sum + a[i];
  }
  cout << min << " " << max << " " << sum;
  cout << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int n, i;
  long mx, mn;
  long sum = 0;
  scanf("%d", &n);
  long a[100000];
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  sum = a[0], mn = a[0], mx = a[0];
  for (i = 1; i < n; i++) {
    if (a[i] > mx) {
      mx = a[i];
    } else if (a[i] < mn) {
      mn = a[i];
    }
    sum += a[i];
  }
  printf("%ld %ld %ld\\n", mn, mx, sum);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int n, i, mx, mn, sum;
  scanf("%d", &n);
  int a[1000];
  for (i = 0; i < n; i++) {
    scanf("%d\\n", &a[i]);
  }
  sum = a[0], mn = a[0], mx = a[0];
  for (i = 1; i < n; i++) {
    if (a[i] > mx) {
      mx = a[i];
    } else if (a[i] < mn) {
      mn = a[i];
    }
    sum += a[i];
  }
  printf("%d %d %d\\n", mn, mx, sum);
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  int n, max, min;
  long sum = 0;
  cin >> n;
  double *a = new double[n];
  for (int j = 0; j < n; j++) {
    cin >> a[j];
  }

  min = a[0];
  max = a[0];

  for (int i = 0; i < n; i++) {
    if (min > a[i]) {
      min = a[i];
    }
    if (max < a[i]) {
      max = a[i];
    }
    sum += a[i];
  }
  delete[] a;
  cout << min << " " << max << " " << sum << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, max, min, sum = 0;
  cin >> n;
  double *a = new double[n];
  cin >> a[n];
  max = a[0];
  min = a[0];

  for (int i = 0; i < n; i++) {
    if (max < a[i]) {
      max = a[i];
    }
    if (min > a[i]) {
      min = a[i];
    }
    sum += a[i];
  }
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  string input;

  int n;
  getline(cin, input);
  sscanf(input.c_str(), "%d\\n", &n);

  int *a = new int[n];

  getline(cin, input);
  const char *p = input.c_str();

  for (int i = 0; i < n; i++) {
    sscanf(p, "%d", a + i);

    if (i == n - 1)
      break;
    while (*p != ' ')
      p++;
    p++;
  }

  long int min = a[0];
  long int max = a[0];
  long int sum = 0;

  for (int i = 0; i < n; i++) {
    if (min > a[i])
      min = a[i];
    if (max < a[i])
      max = a[i];
    sum += a[i];
  }

  delete[] a;

  printf("%ld %ld %ld\\n", min, max, sum);

  return (0);
}


Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  string input;

  int n;
  getline(cin, input);
  sscanf(input.c_str(), "%d\\n", &n);

  int *a = new int[n];

  getline(cin, input);
  const char *p = input.c_str();

  for (int i = 0; i < n; i++) {
    sscanf(p, "%d", a + i);

    while (*p != ' ' && *p != '\\n')
      p++;
    p++;
  }

  int min = a[0];
  int max = a[0];
  int sum = 0;

  for (int i = 0; i < n; i++) {
    if (min > a[i])
      min = a[i];
    if (max < a[i])
      max = a[i];
    sum += a[i];
  }

  delete[] a;

  printf("%d %d %d\\n", min, max, sum);

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

#include <iostream>

using namespace std;

int main() {
  int num = 0;
  int a[10000] = {};
  long int max = -1000000, min = 1000000, sum = 0;

  cin >> num;

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

    if (max < a[i])
      max = a[i];
    if (min > a[i])
      min = a[i];

    sum += a[i];
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}

Error: -11

Fixed submission:

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

#define PI 3.14159265358979323

int main(int argc, char *argv[]) {
  int N;
  long a[100000000];
  int sum = 0;
  cin >> N;

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

  sort(a, a + N);
  printf("%ld %ld %ld\\n", a[0], a[N - 1], sum);
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int max = -1000001, min = 1000001, data;
  long long sum = 0;
  for (int i = 0; i < num; i++) {
    cin >> data;
    if (min > data) {
      min = data;
    }
    if (max < data) {
      max = data;
    }
    sum += data;
  }

  cout << min << " " << max << " " << sum << endl;
  // printf("%d %d %ld\\n", min, max, sum);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n, x, min, max, sum = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;

    if (i = 0) {
      min = x;
      max = x;
    } else {
      if (min > x) {
        min = x;
      }
      if (max < x) {
        max = x;
      }
    }
  }

  cout << min << ' ' << max << ' ' << sum << endl;

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

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

const int MAX = 1000000;

int main() {
  long long n, x, sum = 0, maxi = -MAX, mini = MAX;
  cin >> n;
  //  assert(n <= 10000);
  for (int i = 0; i < n; i++) {
    cin >> x;
    maxi = max(maxi, x);
    mini = min(mini, x);
    // assert((long long)sum + (long long)x < INT_MAX);
    sum += x;
  }
  cout << mini << ' ' << maxi << ' ' << sum << endl;
}

Error: 0

Fixed submission:

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

const int MAX = 1000000;

int main() {
  int n, x, sum = 0, maxi = -MAX, mini = MAX;
  cin >> n;
  //  assert(n <= 10000);
  for (int i = 0; i < n; i++) {
    cin >> x;
    maxi = max(maxi, x);
    mini = min(mini, x);
    assert((long long)sum + (long long)x < INT_MAX);
    sum += x;
  }
  cout << mini << ' ' << maxi << ' ' << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long n, i, x[10000], mi, ma, l;
  l = 0;
  cin >> n;
  mi = 1000000;
  ma = -1000000;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    ma = max(ma, x[i]);
    mi = min(mi, x[i]);
    l += x[i];
  }
  cout << mi << ' ' << ma << ' ' << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i, j, x[1000];
  int min, max, l;
  l = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  min = max = x[0];
  for (i = 0; i < n; i++) {
    if (max < x[i]) {
      max = x[i];
    } else if (min > x[i]) {
      min = x[i];
    }
    l += x[i];
  }
  cout << min << ' ' << max << ' ' << l << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {

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

  sort(a, a + n);
  cout << a[0] << " " << a[n - 1] << " " << c << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int n, c = 0;
    cin >> n;
    int a[10001];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      c = c + a[i];
    }

    sort(a, a + n);
    cout << a[0] << " " << a[n - 1] << " " << c << endl;
  }
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

long long min(int a, int b) {
  if (a <= b)
    return a;
  else
    return b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);

  long long mi = a.at(0), ma = a.at(0), su = a.at(0);
  for (int i = 1; i < n; i++) {
    mi = min(mi, a.at(i));
    ma = max(ma, a.at(i));
    su += a.at(i);
  }
  cout << mi << " " << ma << " " << su << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  int sum = 0;
  for (int i = 0; i < n; n++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(0) << " " << A.at(n - 1) << " " << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n, a;
  int maxa, mina;
  long long sum;
  maxa = -1000001;
  mina = 1000001;
  sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (maxa < a) {
      maxa = a;
    }
    if (mina > a) {
      mina = a;
    }
    sum += a;
  }
  printf("%d %d %lld\\n", mina, maxa, sum);
  return 0;
}


Error: -11

Fixed submission:

#include <cstdio>

int main() {
  int n, a[10000];
  scanf("%d\\n", n);
  for (int i = 0; i < n; i++) {
    scanf("%d ", a[i]);
  }
  int max, min, sum;
  max = a[0];
  min = a[0];
  sum = a[0];
  for (int j = 1; j < n; j++) {
    if (max < a[j]) {
      max = a[j];
    }
    if (min > a[j]) {
      min = a[j];
    }
    sum += a[j];
  }
  printf("%d %d %d", min, max, sum);
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[10000];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[100];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

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

  int mn = a[0], mx = a[0];

  long long sum = 0;

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

    mn = min(mn, a[i]);

    mx = max(mx, a[i]);
    sum += a[i];
  }

  cout << mn << " " << mx << " " << sum << endl;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

int main() {

  while (1) {

    int a, b;
    string op;
    cin >> a >> op >> b;
    if (op == "?")
      break;

    int ans;
    if (op == "+")
      ans = a + b;
    if (op == "-")
      ans = a - b;
    if (op == "*")
      ans = a * b;
    if (op == "/")
      ans = a / b;

    cout << ans << endl;
  }
}