Cod sursa(job #1565899)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 11 ianuarie 2016 17:08:41
Problema Zeap Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.51 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("zeap.in");
ofstream fout("zeap.out");

const int INF = 1e9;

map < int, int > Map;

int main(){
    int x;
    string S;
    while(fin >> S){
        if(S == "MAX" || S == "MIN"){
            if(Map.size() < 2){
                fout << -1 << "\n";
            } else {
                if(S == "MAX"){
                    fout << (Map.rbegin()) -> first - (Map.begin()) -> first << "\n";
                } else {
                    int D = INF;
                    map < int, int > ::iterator a = Map.begin();
                    map < int, int > ::iterator b = Map.begin();
                    a++;
                    for(; a != Map.end(); a++, b++){
                        D = min(D, a -> first - b -> first);
                    }
                    fout << D << "\n";
                }
            }
        } else {
            fin >> x;
            if(S == "I"){
                if(Map.find(x) == Map.end()){
                    Map[x] = x;
                }
            }
            if(S == "S"){
                if(Map.find(x) == Map.end()){
                    fout << -1 << "\n";
                } else {
                    Map.erase(x);
                }
            }
            if(S == "C"){
                if(Map.find(x) == Map.end()){
                    fout << 0 << "\n";
                } else {
                    fout << 1 << "\n";
                }
            }
        }
    }
    return 0;
}