Cod sursa(job #3327532)

Utilizator SerbanCaroleSerban Carole SerbanCarole Data 4 decembrie 2025 13:11:24
Problema Heapuri Scor 0
Compilator java Status done
Runda Arhiva educationala Marime 1.08 kb
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) throws IOException {
        int[] st = new int[200001];
        int vf = 0;
        File fin = new File("heapuri.in");
        File fout = new File("heapuri.out");
        TreeMap<Integer,Integer> ms = new TreeMap<>();
        int ops, op, x;
        Scanner sc = new Scanner(fin);
        PrintWriter pw = new PrintWriter(fout);
        ops = sc.nextInt();
        for(int i = 1 ; i <= ops ; ++i){
            op = sc.nextInt();
            if(op == 3){
                pw.println(ms.firstKey());
            }else{
                x = sc.nextInt();
                if(op == 1){
                    st[++vf] = x;
                    int val = 0;
                    if(ms.containsKey(x))
                        val = ms.get(x);
                    ms.put(x,val+1);
                }else{
                    int elem = ms.get(st[x]);
                    if(elem == 1)
                        ms.remove(st[x]);
                    else ms.put(st[x],elem-1);
                }
            }
        }
    }
}