题目描述

源代码
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N = 5000;
struct Order
{
double price;
int num;
int sell;
} order[N + 1];
vector<double> pricevec;
int main()
{
char s[10];
int num = 0, t;
while (cin >> s)
{
if (s[0] == 'c')
{
cin >> t;
order[t - 1].sell = -1;
order[num].sell = -1;
}
else
{
cin >> order[num].price >> order[num].num;
if (s[0] == 's')
order[num].sell = 1;
else
order[num].sell = 0;
pricevec.push_back(order[num].price);
}
num++;
}
double ans = 0;
long long maxn = 0;
for (int i = 0; i < pricevec.size(); i++)
{
long long num_s = 0;
long long num_b = 0;
for (int j = 0; j < num; j++)
{
if (order[j].sell == 1 && order[j].price <= pricevec[i])
num_s += (long long)order[j].num;
}
for (int j = 0; j < num; j++)
{
if (order[j].sell == 0 && order[j].price >= pricevec[i])
num_b += (long long)order[j].num;
}
num_s = min(num_s, num_b);
if (num_s > maxn)
{
maxn = num_s;
ans = pricevec[i];
}
else
{
if (num_s == maxn)
ans = max(ans, pricevec[i]);
}
}
printf("%.2f %lld\n", ans, maxn);
return 0;
}