Problem Description
These days Lotus is interested in cultivating potted plants, so she wants to build a greenhouse to meet her research desires.
Lotus placed all of the n pots in the new greenhouse, so all potted plants were in the same environment.
Each plant has an optimal growth temperature range of [l,r] , which grows best at this temperature range, but does not necessarily provide the best research value (Lotus thinks that researching poorly developed potted plants are also of great research value).
Lotus has carried out a number of experiments and found that if the growth temperature of the i-th plant is suitable, it can provide ai units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the bi units of research value; temperatures below the lower limit of the appropriate temperature, can provide ci units of research value.
Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of a , b , c are also known. You need to choose a temperature for the greenhouse based on these information, providing Lotus with the maximum research value.
__NOTICE: the temperature can be any real number.__
Lotus placed all of the n pots in the new greenhouse, so all potted plants were in the same environment.
Each plant has an optimal growth temperature range of [l,r] , which grows best at this temperature range, but does not necessarily provide the best research value (Lotus thinks that researching poorly developed potted plants are also of great research value).
Lotus has carried out a number of experiments and found that if the growth temperature of the i-th plant is suitable, it can provide ai units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the bi units of research value; temperatures below the lower limit of the appropriate temperature, can provide ci units of research value.
Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of a , b , c are also known. You need to choose a temperature for the greenhouse based on these information, providing Lotus with the maximum research value.
__NOTICE: the temperature can be any real number.__
Input
The input includes multiple test cases. The first line contains a single integer
T
, the number of test cases.
The first line of each test case contains a single integer n∈[1,50000] , the number of potted plants.
The next n line, each line contains five integers li,ri,ai,bi,ci∈[1,109] .
The first line of each test case contains a single integer n∈[1,50000] , the number of potted plants.
The next n line, each line contains five integers li,ri,ai,bi,ci∈[1,109] .
Output
For each test case, print one line of one single integer presenting the answer.
Sample Input
1 5 5 8 16 20 12 10 16 3 13 13 8 11 13 1 11 7 9 6 17 5 2 11 20 8 5
Sample Output
83
Source
考虑什么时候会对ans造成影响。
1、当温度从低温进入正常温度
2、当温度从正常温度进入高温
那么我们可以把端点取出来排序。一开始温度为-INF。
然后顺着端点扫过去,如果进入正常温度则-c+a,进入高温则-a+b
对于进入高温的情况我们取右端点+0.5保证可以考虑到每种情况
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
struct sav
{
bool v;
int x1,x2;
double loc;
bool operator <(sav y) const
{
return loc<y.loc;
}
}p[200001];
int main()
{
int T;
scanf("%d",&T);
while(T>0)
{
T--;
int n;
scanf("%d",&n);
int i;
int l,r,a,b,c;
int tot=0;
long long sum=0;
for(i=1;i<=n;i++)
{
scanf("%d%d%d%d%d",&l,&r,&a,&b,&c);
tot++;
p[tot].loc=l;
p[tot].x1=c;
p[tot].x2=a;
tot++;
p[tot].loc=r+0.5;
p[tot].v=true;
p[tot].x1=a;
p[tot].x2=b;
sum+=c;
}
sort(p+1,p+1+tot);
long long ans=sum;
for(i=1;i<=tot;i++)
{
double d=p[i].loc;
while(p[i].loc==d)
{
if(!p[i].v)
{
sum-=p[i].x1;
sum+=p[i].x2;
}
else
{
sum-=p[i].x1;
sum+=p[i].x2;
}
i++;
//ans=max(ans,sum);
}
i--;
ans=max(ans,sum);
}
printf("%lld\n",ans);
}
return 0;
}