直接O($n^2$)枚举即可
对于枚举的价格 排序后去个重会快很多
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 10010;
bool st[maxn];
typedef struct node
{
string op;
double price, number;
}Node;
Node operate[maxn];
vector<double> prices;
int n;
int main()
{
string op;
double price, number;
while(cin >> op){
if(op == "cancel") {
int x; cin >> x;
st[x] = true;
st[ ++ n] = true;
}else{
cin >> price >> number;
prices.push_back(price);
operate[ ++ n] = {op, price, number};
}
}
double p = 0;
LL res = 0;
sort(prices.begin(), prices.end());
prices.erase(unique(prices.begin(), prices.end()), prices.end());
for(int i = 0; i < prices.size(); i ++){
auto price = prices[i];
LL cnt1 = 0, cnt2 = 0;
for(int j = 1; j <= n; j ++){
if(st[j]) continue;
auto t = operate[j];
if(t.op == "buy" && t.price >= price){
cnt1 += t.number;
}else if(t.op == "sell" && price >= t.price){
cnt2 += t.number;
}
}
LL cnt = min(cnt1, cnt2);
if(cnt > res || cnt == res && p < price) {
res = cnt;
p = price;
}
}
printf("%.2lf %lld\n", p, res);
return 0;
}