Dogs' Candies
Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 2193 Accepted Submission(s): 542
Problem Description
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.
Input
The input consists of at most 10 test cases. For each test case, the first line contains an integer n indicating that there are n candy box operations(1 <= n <= 50000).
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.
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.
Output
For each operation in which t equals to 0, you should print the maximal deliciousness degree of the best candy for the dog.
Sample Input
61 2 11 1 21 1 10 2 1-1 2 10 2 10
Sample Output
54
Source
题意:
一个狗国家的狗国王有一个装糖的盒子,每颗糖有两个属性p,q,分别代表甜度和咸度,每只狗对于甜度和咸度的偏爱度不一样,所以每条狗有两个参数x, y,每颗糖对于特定的狗的美味度等于p*x+q*y。现在有50000个操作,分为三种:
- 将新的糖(p,q)放入盒子中
- 将盒子中存在的糖(p,q)吃掉
- 给出一条狗的参数(x,y),询问当前存在的糖的最大美味度。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 0x3f3f3f3f
#define NN 500010
using namespace std;
struct ac
{
long long a,b,c;
}r[NN];
int main()
{
int n;
while(cin>>n)
{
if(n==0)
break;
long long len=0;
long long p,q,t;
for(long long j=0;j<n;j++)
{
cin>>t>>p>>q;
if(t==1)
{
r[len].a=p;
r[len].b=q;
r[len++].c=1;
}
else if(t==0)
{
long long maxx=-N;
for(long long i=0;i<len;i++)
{
if(r[i].c==1)
{
maxx=max(maxx,p*r[i].a+q*r[i].b);
}
}
cout<<maxx<<endl;
}
else
{
for(long long i=0;i<len;i++)
{
if(r[i].a==p&&r[i].b==q&&r[i].c==1)
{
r[i].c=0;
break;
}
}
}
}
}
return 0;
}