Pagini recente » Cod sursa (job #318841) | Cod sursa (job #1103449) | Cod sursa (job #1192105) | Cod sursa (job #172082) | Cod sursa (job #1565899)
#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;
}