C Solution - Heap
c []\nvoid push(int **heap, int *new, int top)\n{\n  heap[top] = new;\n  int now = top;\n  int *temp;\n  int next = (top - 1) / 2;\n  while (top)\n  {\n    if (
```c []\nvoid push(int **heap, int *new, int top)\n{\n  heap[top] = new;\n  int now = top;\n  int *temp;\n  int next = (top - 1) / 2;\n  while (top)\n  {\n    if (heap[now][2] > heap[next][2])\n    {\n      temp = heap[next];\n      heap[next] = heap[now];\n      heap[now] = temp;\n      now = next;\n      next = (now - 1) / 2;\n    }\n    else\n      return;\n  }\n}\n\nvoid pop(int **heap, int top)\n{\n  heap[0] = heap[top];\n  int now = 0;\n  int next;\n  int *temp;\n  int left = 1;\n  int right = 2;\n  while (left < top)\n  {\n    next = top == right ? left : ((heap[left][2] > heap[right][2]) ? left : right);\n    if (heap[next][2] > heap[now][2])\n    {\n      temp = heap[next];\n      heap[next] = heap[now];\n      heap[now] = temp;\n      now = next;\n      left = now * 2 + 1;\n      right = now * 2 + 2;\n    }\n    else\n      return;\n  }\n}\n\nint cmp(const void *ptr1, const void *ptr2)\n{\n  int **iptr1 = (int **)ptr1;\n  int **iptr2 = (int **)ptr2;\n\n  if ((*iptr1)[1] > (*iptr2)[1])\n    return 1;\n  if ((*iptr1)[1] == (*iptr2)[1] && (*iptr1)[0] > (*iptr2)[0])\n    return 1;\n  return -1;\n}\n\nint maxTwoEvents(int **events, int eventsSize, int *eventsColSize)\n{\n  int ans = 0, top = 0, temp;\n  int **heap = (int **)malloc(sizeof(int *) * eventsSize);\n  bzero(heap, sizeof(int *) * eventsSize);\n\n  // sort by endTime (events[i][1])\n  qsort(events, eventsSize, sizeof(int *), cmp);\n\n  for (int i = 0; i < eventsSize; i++)\n  {\n    push(heap, events[i], top++);\n  }\n\n  for (int i = 0; i < eventsSize; i++)\n  {\n    while (top > 0 && heap[0][0] <= events[i][1])\n    {\n      pop(heap, --top);\n    }\n\n    temp = events[i][2] + (top > 0 ? heap[0][2] : 0);\n    ans = ans > temp ? ans : temp;\n  }\n\n  return ans;\n}\n```
['C']