0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-05 16:18:48 +00:00
OI-codes/Luogu/P1486/P1486.cpp
2022-03-05 16:23:42 +08:00

36 lines
875 B
C++

#include <algorithm>
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
int n, min, k, c, cnt;
char op;
std::vector<int> a;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> min;
while (n--) {
cin >> op >> k;
if (op == 'I') {
if (k >= min) {
a.insert(std::lower_bound(a.begin(), a.end(), k - c), k - c);
}
} else if (op == 'A') {
c += k;
} else if (op == 'S') {
c -= k;
auto it = std::lower_bound(a.begin(), a.end(), min - c);
cnt += it - a.begin();
a.erase(a.begin(), std::lower_bound(a.begin(), a.end(), min - c));
} else { // op == 'F'
cout << (a.size() < k ? -1 : *(a.end() - k) + c) << endl;
}
}
cout << cnt << endl;
return 0;
}