diff --git a/code_study/Baekjoon/c/11286.c b/code_study/Baekjoon/c/11286.c new file mode 100644 index 0000000..5487897 --- /dev/null +++ b/code_study/Baekjoon/c/11286.c @@ -0,0 +1,73 @@ +#include +#include + +void swap(int *a, int *b); +void insert(int value, int *heap, int* size); +void delete(int *heap, int* size); + +int main(){ + int N; + scanf("%d",&N); + int *heap = (int*)malloc(sizeof(int)*(N+1)); + int heap_size = 0; + while(N--){ + int op; + scanf("%d",&op); + if(op==0) delete(heap, &heap_size); + else insert(op, heap, &heap_size); + } + + free(heap); + return 0; +} + +void swap(int *a, int *b){ + int temp = *a; + *a = *b; + *b = temp; +} + +void insert(int value, int *heap, int* size){ + heap[++(*size)] = value; + int current = *size; + while(current != 1){ + if((abs(heap[current]) < abs(heap[current/2]) || + (abs(heap[current]) == abs(heap[current/2]) && heap[current] absHeap = new PriorityQueue<>((a,b) -> { + if(Math.abs(a) == Math.abs(b)) { + return a - b; + } + return Math.abs(a) - Math.abs(b); + }); + int N = sc.nextInt(); + + for(int i = 0; i