这道题数据量很小,所以用前缀和直接暴力解决了
首先将浮点数转换为整数;
int_p=(int)(dou_p*100+0.5); 必须加一个eps,否则浮点数运算会有误差
然后从高到低枚举
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+;
const int M=;
struct node {
bool by;
int p; LL num;
};
node t[M];
bool flag[M];
LL sum1[N], sum2[N];
int main ()
{
string str; int i=,p_max=,p_min=0x3f3f3f3f;
while (cin>>str) {
i++;
if (str[]=='c') { int x; cin>>x; flag[x]=; }
else {
double p;
cin>>p>>t[i].num;
if (str[]=='b') t[i].by=;
t[i].p=(int)(p*+0.5);
p_max=max (p_max,t[i].p);
p_min=min (p_min,t[i].p);
}
}
int n=i;
for (i=;i<=n;i++)
if (!flag[i]) {
if (t[i].by) sum1[t[i].p]+=t[i].num;
else sum2[t[i].p]+=t[i].num;
}
for (int i=;i<N;i++) {
sum1[i]+=sum1[i-];
sum2[i]+=sum2[i-];
}
LL sum=; int ans;
for (int i=p_max;i>=p_min;i--) {
LL x=min (sum1[N-]-sum1[i-],sum2[i]);
if (x>sum) { sum=x; ans=i; }
}
int a1=ans/,a2=ans%;
printf("%d.%02d %lld\n",a1,a2,sum);
return ;
}