ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1306. Sequence Median

Getting MLE for this:||
Posted by Reza Gharaghani 15 Jun 2021 13:14
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX_N 250000

int n, i, t1, t2;
int *heap;

int main(){
    scanf("%d", &n);
    heap = new int[n/2+2];
    for(i = 0; i < n/2+1; ++i){
        scanf("%d", heap+i);
        push_heap(heap, heap+i+1);
    }

    for(i = 0; i < n/2-(n+1)%2; ++i){
        scanf("%d", heap+n/2+1);
        push_heap(heap, heap+n/2+2);
        pop_heap(heap, heap+n/2+2);
    }

    if(n%2){
        printf("%d.0\n", heap[0]);
    }else{
        t1 = heap[0];
        pop_heap(heap, heap+n/2+1);
        t2 = heap[0];
        if((t1+t2)%2){
            printf("%d.5\n", t1/2+t2/2);
        }else{
            printf("%d.0\n", t1/2+t2/2+t1%2);
        }
    }
    delete[] heap;

    return 0;
}