AcWing 3209. 集合竞价(暴力枚举)
原题链接
简单
作者:
把这题Ac了
,
2024-11-19 10:38:29
,
所有人可见
,
阅读 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 5010;
struct node{
int type;
double p;
int s;
bool is_del;
}cnt[N];
int n;
string op;
double price,total;
int main(){
while(cin >> op){
if(op == "buy"){
double price;
int s;
cin >> price >> s;
cnt[++n] = {1,price,s};
}else if(op == "sell"){
double price;
int s;
cin >> price >> s;
cnt[++n] = {2,price,s};
}else{
int id;
cin >> id;
cnt[id].is_del = true;
cnt[++n].is_del = true;
}
}
double res;
LL total = 0,temp;
for(int i = 1;i <= n;i++){
if(cnt[i].is_del == false){
double p = cnt[i].p;
LL s1 = 0,s2 = 0;
for(int j = 1;j <= n;j++){
if(cnt[j].is_del == false){
if(cnt[j].type == 1 && cnt[j].p >= p) s1 += cnt[j].s;
else if(cnt[j].type == 2 && cnt[j].p <= p) s2 += cnt[j].s;
}
}
temp = min(s1,s2);
if(total < temp || res < p && temp == total){
total = temp;
res = p;
}
}
}
printf("%.2lf %lld\n",res,total);
return 0;
}