Lotus and Horticulture
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 165 Accepted Submission(s): 63
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
这几天Lotus对培养盆栽很感兴趣,于是她想搭建一个温室来满足她的研究欲望。 Lotus将所有的n株盆栽都放在新建的温室里,所以所有盆栽都处于完全相同的环境中。 每一株盆栽都有一个最佳生长温度区间[l,r],在这个范围的温度下生长会生长得最好,但是不一定会提供最佳的研究价值(Lotus认为研究发育不良的盆栽也是很有研究价值的)。 Lotus进行了若干次试验,发现若第i株盆栽的生长温度适宜,可以提供ai的研究价值;若生长温度超过了适宜温度的上限,能提供bi的研究价值;若生长温度低于适宜温度的下限,则能提供ci的研究价值。 现在通过试验,Lotus已经得知了每一株盆栽的适宜生长温度范围,也知道了它们的a、b、c的值。你需要根据这些信息,给温室选定一个温度(这个温度可以是任意实数),使得Lotus能获得的研究价值最大。
每一盆植物给一个区间,温度在区间中的价值a,超过为b,低于为c,求最大价值;因为这题区间特别大,所以需要离散化处理,将区间缩成点,首先算出低于区间的
价值和,每遇到一条边就加上他的值,相当于用一条竖直扫描线来计算处于每个区间的价值和,思维很巧妙;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
typedef long long LL;
struct node
{
int l, v;
}p[N];
int cmp(node A,node B)
{
return A.l<B.l;
}
LL maxt(LL a,LL b)
{
return a>b?a:b;
}
int main()
{
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
LL ans=0, res=0;
int k=0, l, r, a, b, c;
for(int i=0;i<n;i++)
{
scanf("%d %d %d %d %d", &l, &r, &a, &b, &c);
p[++k].l=l*2;
p[k].v=a-c;
p[++k].l=r*2+1;
p[k].v=b-a;
ans+=c;
}
sort(p+1,p+k+1,cmp);
res=ans;
for(int i=1;i<=k;)
{
res+=p[i].v;
i++;
while(i<=k&&p[i].l==p[i-1].l) res+=p[i].v, i++;
ans=maxt(ans,res);
}
printf("%lld\n",ans);
}
return 0;
}