#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5010;
struct node{
string type;
double p;
int num;
};
node rec[N], sell[N], buy[N];
bool cmp_buy(node a, node b){
return a.p > b.p;
}
bool cmp_sell(node a, node b){
return a.p < b.p;
}
int main(){
string str;
double p;
int num, n = 0, bn = 0, sn = 0;
while(cin >> str){
if (str != "cancel"){
cin >> rec[n].p >> rec[n].num;
rec[n].type = str;
n ++;
}
else{
int del;
cin >> del;
rec[n].type = str;
rec[n].num = del;
n ++;
}
}
// cout << 1 << endl;
for (int i = n - 1; i >= 0; i --){
if (rec[i].type == "cancel"){
if (rec[rec[i].num - 1].type != "cancel"){
rec[rec[i].num - 1].type = "";
}
}else if (rec[i].type == "buy"){
buy[bn] = rec[i], bn ++;
}else if (rec[i].type == "sell"){
sell[sn] = rec[i], sn ++;
}
}
sort(rec, rec + n, cmp_buy);
sort(buy, buy + bn, cmp_buy);
sort(sell, sell + sn, cmp_sell);
// for (int i = 0; i < sn; i ++){
// cout << sell[i].type << sell[i].p << sell[i].num << endl;
// }
//cout << 2 << endl;
double p0, suc_p;
long long buy_num = 0, sell_num = 0, temp_num = 0, suc_num = 0;
for (int i = 0; i < n; i ++){
if (rec[i].p == 0) break;
buy_num = 0;
sell_num = 0;
p0 = rec[i].p;
for (int j = 0; j < bn; j ++){
if (buy[j].p < p0) break;
else buy_num += buy[j].num;
}
for (int j = 0; j < sn; j ++){
if (sell[j].p > p0) break;
else sell_num += sell[j].num;
}
// cout << i << " " << p0 << endl;
temp_num = min(buy_num, sell_num);
// cout << i <<" " <<temp_num << endl;
if (temp_num > suc_num){
suc_num = temp_num;
suc_p = p0;
}
}
printf("%.2f %lld\n", suc_p, suc_num);
return 0;
}
201412-3------------集合竞价
最新推荐文章于 2021-09-05 15:07:41 发布