Cod sursa(job #2809630)

Utilizator andreipirjol5Andrei Pirjol andreipirjol5 Data 27 noiembrie 2021 11:51:16
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include <stdio.h>
#include <algorithm>

using namespace std ;

#define NMAX 200000
int v[NMAX + 5] , v1[NMAX + 5] ;
int n ;

void insert_element (int x)
{
    n++;
    v[n] = x ;
}

void delete_element (int x)
{
    for(int i = x ; i <= n ; i++)
        v[i] = v[i + 1] ;
    n--;
}

int minim ()
{
    for(int i = 1 ; i <= n ; i++)
        v1[i] = v[i] ;

    sort(v1 + 1, v1 + n + 1) ;

    return v1[1] ;
}
int main()
{
    FILE *fin, *fout ;
    fin = fopen("heapuri.in", "r") ;
    fout = fopen("heapuri.out", "w") ;
    int n ;
    fscanf(fin, "%d", &n) ;

    for(int t = 1 ; t <= n ; t++)
    {
        int operation ;
        fscanf(fin, "%d", &operation) ;
        if(operation == 1)
        {
            int x ;
            fscanf(fin, "%d", &x) ;
            insert_element(x) ;
        }
        else if(operation == 2)
        {
            int x ;
            fscanf(fin, "%d", &x) ;
            delete_element(x) ;
        }
        else if(operation == 3)
            fprintf(fout, "%d\n", minim()) ;
    }

    fclose(fin) ;
    fclose(fout) ;
    return 0 ;
}