Far far away, there live a lot of dogs in the forest. Unlike other dogs, those dogs love candies much more than bones.
Every candy has two attributes: the sweetness degree p and the sourness degree q. Different dogs like different candies. A dog also has two attributes: the fondness degree for sweetness x and the fondness degree for sourness y. So the deliciousness degree of a candy for a dog is defined as p×x + q×y.
The dog king has a huge candy box. At first, the box is empty. The king can add candies to the box or take some candies from the box and eat them. There are always some dogs who want to know which candies in the box are the most delicious for them. Please help the king to answer their questions.
Every candy has two attributes: the sweetness degree p and the sourness degree q. Different dogs like different candies. A dog also has two attributes: the fondness degree for sweetness x and the fondness degree for sourness y. So the deliciousness degree of a candy for a dog is defined as p×x + q×y.
The dog king has a huge candy box. At first, the box is empty. The king can add candies to the box or take some candies from the box and eat them. There are always some dogs who want to know which candies in the box are the most delicious for them. Please help the king to answer their questions.
The following n lines describe the n operations.
Each operation contains three integers t, x and y( 0 <= |x|, |y| <= 109). The first integer t may be -1, 0, or 1.
If t equals -1, it means that a candy in the box with sweetness degree x and sourness degree y is eaten by the dog king.
If t equals 1, it means that a candy with sweetness degree x and sourness degree y is added to the candy box.
If t equals 0, it means that a dog with sweetness fondness degree x and sourness fondness degree y wants to know the maximal deliciousness degree of the candies in the box for him.
It is guaranteed that every candy is unique in the box.
The input ends by n = 0.
6 1 2 1 1 1 2 1 1 1 0 2 1 -1 2 1 0 2 1 0
54
直接暴力过
#include<stdio.h>
#include<string.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int MAXN = 1e7+10;
#define inf 0x3f3f3f3f
struct node
{
char s[2];
LL tian,suan;
}a[50005];
LL we[50005];
LL ni[50005];
LL ta[50005];
LL tata[50005];
int main()
{
int n;
while(scanf("%d",&n)!=-1)
{
if(n==0)
break;
for(int i=0;i<n;i++)
{
scanf("%s %lld %lld",a[i].s,&a[i].tian,&a[i].suan);
}
int p=0;
int ha=0;
memset(we,0,sizeof(we));
memset(ni,0,sizeof(ni));
for(int i=0;i<n;i++)
{
if(strcmp(a[i].s,"1")==0)
{
we[p]=a[i].tian;
ni[p++]=a[i].suan;
}
else if(strcmp(a[i].s,"0")==0)
{
LL maxn=-inf;
for(int j=0;j<p;j++)
{
maxn=max(maxn,we[j]*a[i].tian+ni[j]*a[i].suan);
}
printf("%lld\n",maxn);
}
else if(strcmp(a[i].s,"-1")==0)
{
memset(ta,0,sizeof(ta));
memset(tata,0,sizeof(tata));
ha=0;
for(int k=0;k<p;k++)
{
if(we[k]!=a[i].tian||ni[k]!=a[i].suan)
{
ta[ha]=we[k];
tata[ha++]=ni[k];
}
}
memset(we,0,sizeof(we));
memset(ni,0,sizeof(ni));
p=0;
for(int l=0;l<ha;l++)
{
we[p]=ta[l];
ni[p++]=tata[l];
}
}
}
}
}