Pagini recente » Cod sursa (job #2549573) | Cod sursa (job #2285980) | Cod sursa (job #2901525) | Cod sursa (job #2687357) | Cod sursa (job #3129460)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
set<int> zeap;
int main() {
freopen("zeap.in", "r", stdin);
freopen("zeap.out", "w", stdout);
string op;
while (cin >> op) {
if (op == "I") {
int x;
cin >> x;
zeap.insert(x);
} else if (op == "S") {
int x;
cin >> x;
if (zeap.find(x) != zeap.end()) {
zeap.erase(x);
} else {
cout << -1 << '\n';
}
} else if (op == "C") {
int x;
cin >> x;
if (zeap.find(x) != zeap.end()) {
cout << 1 << '\n';
} else {
cout << 0 << '\n';
}
} else if (op == "MAX") {
if (zeap.size() < 2) {
cout << -1 << '\n';
} else {
int max_dif = *(--zeap.end()) - *(zeap.begin());
cout << max_dif << '\n';
}
} else if (op == "MIN") {
if (zeap.size() < 2) {
cout << -1 << '\n';
} else {
int min_dif = INT_MAX;
for (auto it = zeap.begin(); next(it) != zeap.end(); ++it) {
min_dif = min(min_dif, abs(*next(it) - *it));
}
cout << min_dif << '\n';
}
}
}
return 0;
}