排序+双指针,还ok
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct pii {
pair<double, int> pi;
int type;
};
vector<pair<double, int>> buy;
vector<pair<double, int>> sell;
vector<pii> vec;
vector<bool> cac(5010, false);
signed main(){
char op[10];
double p;
int fc;
int buy_tot = 0;
while (scanf("%s", op) != EOF) {
if (op[0] == 'b') {
scanf("%lf%lld",&p,&fc);
vec.push_back({make_pair(p, fc), 0});
} else if (op[0] == 's') {
scanf("%lf%lld",&p,&fc);
vec.push_back({make_pair(p, fc), 1});
} else {
scanf("%lld",&fc);
cac[fc - 1] = !cac[fc - 1];
vec.push_back({make_pair(-1.0, fc), 2});
}
}
for (int i = 0; i < (int)vec.size(); i++) {
if (!cac[i]) {
if (vec[i].type == 0) {
buy_tot += vec[i].pi.second;
buy.push_back(vec[i].pi);
} else if (vec[i].type == 1) {
sell.push_back(vec[i].pi);
}
}
}
sort(buy.begin(), buy.end());
sort(sell.begin(), sell.end());
double ret = 0;
int tot_cnt = 0;
int cnt_buy = 0, cnt_sell = 0;
int r = 0;
for (int i = 0; i < (int)buy.size(); i++) {
while (r < (int)sell.size() && sell[r].first <= buy[i].first) {
cnt_sell += sell[r].second;
r++;
}
if (r == 0) {
cnt_buy += buy[i].second;
continue;
}
if (min(cnt_sell, buy_tot - cnt_buy) == tot_cnt) {
ret = max(ret, buy[i].first);
} else if (min(cnt_sell, buy_tot - cnt_buy) > tot_cnt) {
tot_cnt = min(cnt_sell , buy_tot - cnt_buy);
ret = max(ret, buy[i].first);
}
cnt_buy += buy[i].second;
}
printf("%.2lf %lld", ret, tot_cnt);
}