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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<vector<bool>> matb;
typedef vector<string> vst;
typedef pair<lli, lli> pll;
typedef pair<double, double> pdd;

lli h;
vll a;

void max_heapify(lli i) {
  lli l = i * 2;
  lli r = i * 2 + 1;
  lli est = max({i, r, l}, [](lli s, lli t) {
    if (s > h)
      return true;
    if (t > h)
      return false;
    return a[s] < a[t];
  });
  swap(a[i], a[est]);
  if (i != est)
    max_heapify(est);
}

int main() {
  cin >> h;
  a = vll(h + 1);
  for (lli i = 1; i <= h; i++)
    cin >> a[i];
  for (lli i = h; i > 0; i--)
    max_heapify(i);
  for (lli i = 1; i <= h; i++)
    cout << " " << a[i];
  cout << endl;
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<vector<bool>> matb;
typedef vector<string> vst;
typedef pair<lli, lli> pll;
typedef pair<double, double> pdd;

lli h;
vll a;

void max_heapify(lli i) {
  lli l = i * 2;
  lli r = i * 2 + 1;
  lli est = max({i, r, l}, [](lli s, lli t) { return a[s] < a[t]; });
  swap(a[i], a[est]);
  if (i != est)
    max_heapify(est);
}

int main() {
  cin >> h;
  a = vll(h + 1);
  for (lli i = 1; i <= h; i++)
    cin >> a[i];
  for (lli i = h; i > 0; i--)
    max_heapify(i);
  for (lli i = 1; i <= h; i++)
    cout << " " << a[i];
  cout << endl;
  return 0;
}
Problem p02288 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

constexpr size_t MAX_HEAP_SIZE = 500000;
;
int H[MAX_HEAP_SIZE + 1];

int parent(int i) { return i / 2; }

int left(int i) { return i * 2; }

int right(int i) { return i * 2 + 1; }

int MaxHeapify(int *H, int i, int heap_size) {
  int l = left(i);
  int r = right(i);
  int largest;
  if ((l <= heap_size) && (H[l]) > H[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if ((r <= heap_size) && (H[r] > H[largest])) {
    largest = r;
  }
  if (largest != i) {
    std::swap(H[i], H[largest]);
    MaxHeapify(H, largest, heap_size);
  }
  return 0;
}

int BuildMaxHeap(int *H, int heap_size) {
  for (int i = heap_size / 2; i > 0; i--) {
    MaxHeapify(H, i, heap_size);
  }
  return 0;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++)
    std::cin >> H[i];
  BuildMaxHeap(H, n);
  for (int i = 1; i <= n; i++) {
    std::cout << " ";
    std::cout << H[i];
  }
  std::cout << std::endl;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

constexpr size_t MAX_HEAP_SIZE = 250;
int H[MAX_HEAP_SIZE + 1];

int parent(int i) { return i / 2; }

int left(int i) { return i * 2; }

int right(int i) { return i * 2 + 1; }

int MaxHeapify(int *H, int i, int heap_size) {
  int l = left(i);
  int r = right(i);
  int largest;
  if ((l <= heap_size) && (H[l]) > H[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if ((r <= heap_size) && (H[r] > H[largest])) {
    largest = r;
  }
  if (largest != i) {
    std::swap(H[i], H[largest]);
    MaxHeapify(H, largest, heap_size);
  }
  return 0;
}

int BuildMaxHeap(int *H, int heap_size) {
  for (int i = heap_size / 2; i > 0; i--) {
    MaxHeapify(H, i, heap_size);
  }
  return 0;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++)
    std::cin >> H[i];
  BuildMaxHeap(H, n);
  for (int i = 1; i <= n; i++) {
    std::cout << " ";
    std::cout << H[i];
  }
  std::cout << std::endl;
}
Problem p02289 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct priority_queue {
  int A[2001005];
  int fact;
  priority_queue() {
    for (int i = 0; i < 2001005; i++) {
      A[i] = -1;
    }
    fact = 0;
  }
  int extract() {
    int ret = A[0];
    A[0] = A[--fact];
    A[fact] = -1;
    int start = 0;
    while (start * 2 + 1 < fact) {
      int c1 = start * 2 + 1, c2 = start * 2 + 2;
      int next = c2;
      if (A[c1] > A[c2]) {
        next = c1;
      }
      if (A[next] > A[start]) {
        int temp = A[next];
        A[next] = A[start];
        A[start] = temp;
        start = next;
      } else {
        break;
      }
    }
    return ret;

    return ret;
  }
  void insert(int x) {
    int start = fact;
    fact++;
    A[start] = x;
    while (start > 0) {
      int p = (start - 1) / 2;
      if (A[start] > A[p]) {
        int temp = A[start];
        A[start] = A[p];
        A[p] = temp;
      }
      start = p;
    }
    return;
  }
};

int main() {
  priority_queue pq;
  char s[100];
  while (1) {
    scanf("%s", s);
    if (!strcmp(s, "extract")) {
      printf("%d\\n", pq.extract());
    } else if (!strcmp(s, "end")) {
      break;
    } else {
      int x;
      scanf("%d", &x);
      pq.insert(x);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct priority_queue {
  int A[2100005];
  int fact;
  priority_queue() {
    for (int i = 0; i < 2100005; i++) {
      A[i] = -1;
    }
    fact = 0;
  }
  int extract() {
    int ret = A[0];
    A[0] = A[--fact];
    A[fact] = -1;
    int start = 0;
    while (start * 2 + 1 < fact) {
      int c1 = start * 2 + 1, c2 = start * 2 + 2;
      int next = c2;
      if (A[c1] > A[c2]) {
        next = c1;
      }
      if (A[next] > A[start]) {
        int temp = A[next];
        A[next] = A[start];
        A[start] = temp;
        start = next;
      } else {
        break;
      }
    }
    return ret;

    return ret;
  }
  void insert(int x) {
    int start = fact;
    fact++;
    A[start] = x;
    while (start > 0) {
      int p = (start - 1) / 2;
      if (A[start] > A[p]) {
        int temp = A[start];
        A[start] = A[p];
        A[p] = temp;
      }
      start = p;
    }
    return;
  }
};

int main() {
  priority_queue pq;
  char s[100];
  while (1) {
    scanf("%s", s);
    if (!strcmp(s, "extract")) {
      printf("%d\\n", pq.extract());
    } else if (!strcmp(s, "end")) {
      break;
    } else {
      int x;
      scanf("%d", &x);
      pq.insert(x);
    }
  }
  return 0;
}
Problem p02289 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  priority_queue<int> que;
  char str[128];
  while (scanf("%s", str) && str[2] != 'd') {
    if (str[0] == 'i') {
      int key;
      scanf("%d", &key);
      que.push(key);
    } else {
      printf("%d\\n", que.top());
      que.pop();
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {
  priority_queue<int> que;
  string str;
  while (cin >> str && str != "end") {
    if (str[0] == 'i') {
      int key;
      cin >> key;
      que.push(key);
    } else {
      cout << que.top() << endl;
      que.pop();
    }
  }
}
Problem p02289 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#define MAX_NODES 2000000
#define INFTY 2000000010

using namespace std;
// think easy make easy
// think stupid

int n = 0; // num of nodes

// iを根とするMaxヒープをつくる関数.初期状態はiを根とする二分木
void maxHeapify(int A[], int i) { // i is index of root
  int l, r;
  int largest;
  int tmp;

  l = 2 * i;
  r = l + 1;

  if (l <= n && A[l] > A[i])
    largest = l;
  else
    largest = i;

  if (r <= n && A[r] > A[largest])
    largest = r;

  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int A[]) { // AをMaxヒープにする関数
  for (int i = n / 2; i > 0;
       i--) { // 1~n/2が左右の子少なくとも一方が存在する範囲
    maxHeapify(A, i);
  }
}

void heapIncreasingKey(int A[]) {
  int tmp;
  int tmp_n;
  for (int i = n; i > 1; i = i / 2) {
    if (A[i / 2] < A[i]) {
      tmp = A[i];
      A[i] = A[i / 2];
      A[i / 2] = tmp;
    } else
      break;
  }
}

void insert(int A[], int num) {
  n++;
  A[n] = num;
  heapIncreasingKey(A);
}

void extract(int A[]) {
  cout << A[1] << endl;
  A[1] = A[n];
  n--;
  maxHeapify(A, 1);
}

void swap() {}
int main() {
  // 1オリジン(添え字が1からはじまる)のためナル文字分の+1に加えさらに+1する
  int H[MAX_NODES + 1 + 1];
  int num;
  char type[100];

  while (true) {
    scanf("%s", &type);

    if (type[0] == 'i') {
      scanf("%d", &num);
      insert(H, num);
    } else if (type[1] == 'x') {
      extract(H);
    } else
      break;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdio.h>
#define MAX_NODES 2000000
#define INFTY 2000000010

using namespace std;
// think easy make easy
// think stupid

int n = 0; // num of nodes

// iを根とするMaxヒープをつくる関数.初期状態はiを根とする二分木
void maxHeapify(int A[], int i) { // i is index of root
  int l, r;
  int largest;
  int tmp;

  l = 2 * i;
  r = l + 1;

  if (l <= n && A[l] > A[i])
    largest = l;
  else
    largest = i;

  if (r <= n && A[r] > A[largest])
    largest = r;

  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int A[]) { // AをMaxヒープにする関数
  for (int i = n / 2; i > 0;
       i--) { // 1~n/2が左右の子少なくとも一方が存在する範囲
    maxHeapify(A, i);
  }
}

void heapIncreasingKey(int A[]) {
  int tmp;
  int tmp_n;
  for (int i = n; i > 1; i = i / 2) {
    if (A[i / 2] < A[i]) {
      tmp = A[i];
      A[i] = A[i / 2];
      A[i / 2] = tmp;
    } else
      break;
  }
}

void insert(int A[], int num) {
  n++;
  A[n] = num;
  heapIncreasingKey(A);
}

void extract(int A[]) {
  cout << A[1] << endl;
  n--;
  A[1] = A[n];
  n--;
  maxHeapify(A, 1);
}

void swap() {}
int main() {
  // 1オリジン(添え字が1からはじまる)のためナル文字分の+1に加えさらに+1する
  int H[MAX_NODES + 1 + 1];
  int num;
  char type[100];

  while (true) {
    scanf("%s", &type);

    if (type[0] == 'i') {
      scanf("%d", &num);
      insert(H, num);
    } else if (type[1] == 'x') {
      extract(H);
    } else
      break;
  }

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

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

template <typename T> class PQueue {
private:
  vector<T> data;

public:
  PQueue() { data.push_back(0); }
  T insert(T k);
  T extractMax();
};

template <typename T> T PQueue<T>::insert(T k) {
  data.push_back(k);
  int n = data.size() - 1;
  while (1) {
    if (n == 1)
      break;
    else if (data[n] <= data[n / 2])
      break;
    else {
      T temp = data[n / 2];
      data[n / 2] = data[n];
      data[n] = temp;
      n /= 2;
    }
  }
  return k;
}

template <typename T> T PQueue<T>::extractMax() {
  assert(data.size() >= 2);
  T top = data[1];
  data[1] = data.back();
  data.pop_back();
  int i = 1;
  while (1) {
    if (i * 2 >= data.size())
      break;
    else if (i * 2 + 1 >= data.size()) {
      if (data[i] >= data[i * 2])
        break;
      else {
        T temp = data[i];
        data[i] = data[i * 2];
        data[i * 2] = temp;
      }
    } else {
      if (data[i] >= max(data[i * 2], data[i * 2 + 1]))
        break;
      else if (data[i * 2] >= data[i * 2 + 1]) {
        T temp = data[i];
        data[i] = data[i * 2];
        data[i * 2] = temp;
        i *= 2;
      } else {
        T temp = data[i];
        data[i] = data[i * 2 + 1];
        data[i * 2 + 1] = temp;
        i = i * 2 + 1;
      }
    }
  }
  return top;
}

int main() {
  PQueue<int> pq;
  string command;
  int n;
  while (cin >> command && command != "end") {
    if (command == "insert") {
      cin >> n;
      pq.insert(n);
    } else if (command == "extract")
      cout << pq.extractMax() << endl;
  }
}


Error: TLE

Fixed submission:

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

template <typename T> class PQueue {
private:
  vector<T> data;
  int s, e;

public:
  PQueue() {
    s = 0;
    e = 0;
    data.resize(10000);
  }
  T insert(T k);
  T extractMax();
  void show_all();
};

template <typename T> T PQueue<T>::insert(T k) {
  if (s == e)
    data[s] = k;
  else {
    auto i = upper_bound(data.begin() + s, data.begin() + e, k);
    data.insert(i, k);
  }
  e++;
  return k;
}

template <typename T> T PQueue<T>::extractMax() {
  assert(s < e);
  return data[--e];
}

template <typename T> void PQueue<T>::show_all() {
  for (int i = s; i < e; i++)
    cout << data[i] << endl;
}

int main() {
  PQueue<int> pq;
  string command;
  int n;
  while (cin >> command && command != "end") {
    if (command == "insert") {
      cin >> n;
      pq.insert(n);
    } else if (command == "extract")
      cout << pq.extractMax() << endl;
    else if (command == "all")
      pq.show_all();
  }
}
Problem p02289 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
class Heap {
public:
  Heap() {
    array = new int[2000000];
    n = 0;
  }
  void insert(int data) {
    array[n] = data;
    int tmp = n;
    while (tmp != 0 && array[tmp] > array[(tmp - 1) / 2]) {
      std::swap(array[tmp], array[(tmp - 1) / 2]);
      tmp = (tmp - 1) / 2;
    }
    n++;
  }
  int extract() {
    int ret = array[0];
    n--;
    std::swap(array[0], array[n]);
    int tmp = 0;
    while (2 * tmp + 1 <= n - 1) {
      if (2 * tmp + 2 <= n - 1) {
        if (array[2 * tmp + 2] > array[tmp] &&
            array[2 * tmp + 2] >= array[2 * tmp + 1]) {
          std::swap(array[2 * tmp + 2], array[tmp]);
          tmp = 2 * tmp + 2;
        } else if (array[2 * tmp + 1] > array[tmp] &&
                   array[2 * tmp + 1] >= array[2 * tmp + 2]) {
          std::swap(array[2 * tmp + 1], array[tmp]);
          tmp = 2 * tmp + 1;
        } else {
          break;
        }
      } else {
        if (array[tmp] < array[2 * tmp + 1]) {
          std::swap(array[tmp], array[2 * tmp + 1]);
          tmp = 2 * tmp + 1;
        } else {
          break;
        }
      }
    }
    return ret;
  }

private:
  int *array;
  int n;
};
int main() {
  int insert_data;
  char buf[22];
  Heap heap;
  while (true) {
    fgets(buf, 22, stdin);
    if (buf[2] == 'd')
      break;
    if (buf[0] == 'i') {
      insert_data = 0;
      for (int i = 0; buf[i] != '\\0'; i++) {
        if (buf[i] >= '0' && buf[i] <= '9') {
          insert_data = 10 * insert_data + (buf[i] - '0');
        }
      }
      heap.insert(insert_data);
    } else {
      printf("%d\\n", heap.extract());
    }
  }
}


Error: TLE

Fixed submission:

#include <stdio.h>
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_C
// heaps--priority queue

// copy the array
// TLE:
int a[2000005];
void maxheapify(int a[], int i, int n) {
  int l = 2 * i;
  int r = 2 * i + 1;
  int largest = 0; // select
  if (l <= n && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if (r <= n && a[r] > a[largest])
    largest = r;
  if (largest != i) {
    int temp = a[i];
    a[i] = a[largest];
    a[largest] = temp;
    maxheapify(a, largest, n);
  }
}
void build_maxheap(int a[], int n) {
  for (int i = n / 2; i >= 1; i--) {
    maxheapify(a, i, n);
  }
}

int main() {
  char s[20];
  int num;
  int tag = 1;   // 0: extract, 1: insert
  int count = 1; // begin from 1
  while (1) {
    scanf("%s", &s);
    if (s[0] == 'i') {
      scanf("%d", &num);
      a[count] = num;
      // build_maxheap(a,count);
      count++;
      tag = 1;
    } else if (s[0] == 'e' && s[1] == 'x') {

      build_maxheap(a, count);
      printf("%d\\n", a[1]);
      for (int i = 1; i < count; i++) {
        a[i] = a[i + 1];
      }

      count--;
      tag = 0;
    } else {
      break;
    }
    /*for(int i = 1; i<count; i++){
            printf("%d ",a[i]);
    }printf("\\n");*/
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct priority_queue {
  int A[2000005];
  int fact;
  priority_queue() {
    for (int i = 0; i < 2000005; i++) {
      A[i] = -1;
    }
    fact = 0;
  }
  int extract() {
    int ret = A[0];
    A[0] = A[--fact];
    A[fact] = -1;
    int start = 0;
    while (start * 2 + 1 < fact) {
      int c1 = start * 2 + 1, c2 = start * 2 + 2;
      int next = c2;
      if (A[c1] > A[c2]) {
        next = c1;
      }
      if (A[next] > A[start]) {
        int temp = A[next];
        A[next] = A[start];
        A[start] = temp;
        start = next;
      } else {
        break;
      }
    }
    return ret;

    return ret;
  }
  void insert(int x) {
    int start = fact;
    fact++;
    A[start] = x;
    while (start > 0) {
      int p = (start - 1) / 2;
      if (A[start] > A[p]) {
        int temp = A[start];
        A[start] = A[p];
        A[p] = temp;
      }
      start = p;
    }
    return;
  }
};

int main() {
  priority_queue pq;
  char s[100];
  while (1) {
    scanf("%s", s);
    if (!strcmp(s, "extract")) {
      printf("%d\\n", pq.extract());
    } else if (!strcmp(s, "end")) {
      break;
    } else {
      int x;
      scanf("%d", &x);
      pq.insert(x);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct priority_queue {
  int A[1 << 21];
  int fact;
  priority_queue() {
    for (int i = 0; i < (1 << 21); i++) {
      A[i] = -1;
    }
    fact = 0;
  }
  int extract() {
    int ret = A[0];
    A[0] = A[--fact];
    A[fact] = -1;
    int start = 0;
    while (start * 2 + 1 < fact) {
      int c1 = start * 2 + 1, c2 = start * 2 + 2;
      int next = c2;
      if (A[c1] > A[c2]) {
        next = c1;
      }
      if (A[next] > A[start]) {
        int temp = A[next];
        A[next] = A[start];
        A[start] = temp;
        start = next;
      } else {
        break;
      }
    }
    return ret;

    return ret;
  }
  void insert(int x) {
    int start = fact;
    fact++;
    A[start] = x;
    while (start > 0) {
      int p = (start - 1) / 2;
      if (A[start] > A[p]) {
        int temp = A[start];
        A[start] = A[p];
        A[p] = temp;
      }
      start = p;
    }
    return;
  }
};

int main() {
  priority_queue pq;
  char s[100];
  while (1) {
    scanf("%s", s);
    if (!strcmp(s, "extract")) {
      printf("%d\\n", pq.extract());
    } else if (!strcmp(s, "end")) {
      break;
    } else {
      int x;
      scanf("%d", &x);
      pq.insert(x);
    }
  }
  return 0;
}
Problem p02289 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
void Insert(int);
void Increase(int, int);
int Extract(void);
void maxHeapify(int i);
int H[1000000];
int n = 0;
int main() {
  int key, n = 0;
  char ch[10];

  while (1) {
    cin >> ch;
    if (ch[0] == 'i') {
      cin >> key;
      Insert(key);
    } else if (ch[0] == 'e' && ch[1] == 'x') {
      cout << Extract() << endl;
    } else {
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << H[i] << endl;
  }
  return 0;
}

void Insert(int key) {
  n += 1;
  H[n] = -1;
  Increase(n, key);
}
void Increase(int i, int key) {
  int tmp;
  H[i] = key;
  while (i > 1 && H[i / 2] < H[i]) {
    tmp = H[i];
    H[i] = H[i / 2];
    H[i / 2] = tmp;
    i = i / 2;
  }
}

int Extract() {
  int max = H[1];
  H[1] = H[n];
  n--;
  maxHeapify(1);
  return max;
}
void maxHeapify(int i) {
  int r, l, largest, tmp;
  l = i * 2;
  r = i * 2 + 1;

  if (l <= n && H[l] > H[i])
    largest = l;
  else
    largest = i;

  if (r <= n && H[r] > H[largest])
    largest = r;

  if (largest != i) {
    tmp = H[i];
    H[i] = H[largest];
    H[largest] = tmp;

    maxHeapify(largest);
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
void Insert(int);
void Increase(int, int);
int Extract(void);
void maxHeapify(int i);
int H[1000];
int n = 0;
int main() {
  int key, n = 0;
  char ch[10];

  while (1) {
    cin >> ch;
    if (ch[0] == 'i') {
      cin >> key;
      Insert(key);
    } else if (ch[0] == 'e' && ch[1] == 'x') {
      cout << Extract() << endl;
    } else {
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << H[i] << endl;
  }
  return 0;
}

void Insert(int key) {
  n += 1;
  H[n] = -1;
  Increase(n, key);
}
void Increase(int i, int key) {
  int tmp;
  H[i] = key;
  while (i > 1 && H[i / 2] < H[i]) {
    tmp = H[i];
    H[i] = H[i / 2];
    H[i / 2] = tmp;
    i = i / 2;
  }
}

int Extract() {
  int max = H[1];
  H[1] = H[n];
  n--;
  maxHeapify(1);
  return max;
}
void maxHeapify(int i) {
  int r, l, largest, tmp;
  l = i * 2;
  r = i * 2 + 1;

  if (l <= n && H[l] > H[i])
    largest = l;
  else
    largest = i;

  if (r <= n && H[r] > H[largest])
    largest = r;

  if (largest != i) {
    tmp = H[i];
    H[i] = H[largest];
    H[largest] = tmp;

    maxHeapify(largest);
  }
}