HDU 6012

来源:互联网 发布:淘宝客服外包怎么样 编辑:程序博客网 时间:2024/06/04 08:09

Lotus and Horticulture
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 692 Accepted Submission(s): 220

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.

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].

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
BestCoder Round #91

贪心即可,假设温度从负无穷大开始递增,于是首先算出所有植物C情况之和,然后对每个点进行排序,如果是L点,则-C+A,如果是R点,则-A+B,同时有两点要注意:1,值相同的点。2.值相同时L,R不同怎么处理,在排序时应先对值排序,如果值相同的情况下,要优先L,然后R。

#include<bits/stdc++.h>using namespace std;struct plant{   long long lor;   long long i;   long long l;   long long r;   long long a,b,c;}p[200005];bool cmp(plant a,plant b){    return a.i==b.i?a.lor<b.lor:a.i<b.i;}int main(){    long long t,n,l,r,a,b,c;    cin>>t;    while(t--)    {        cin>>n;        long long ans=0;        for(long long i=0;i<n;i++)        {            scanf("%lld%lld%lld%lld%lld",&l,&r,&a,&b,&c);            p[i*2].i=l,p[i*2+1].i=r;            p[i*2].lor=0,p[i*2+1].lor=1;            p[i*2].l=p[i*2+1].l=l;            p[i*2].r=p[i*2+1].r=r;            p[i*2].a=p[i*2+1].a=a;            p[i*2].b=p[i*2+1].b=b;            p[i*2].c=p[i*2+1].c=c;            ans+=c;        }        sort(p,p+n*2,cmp);        long long sum=ans;        for(long long i=0;i<2*n;i++)        {            i--;            do {                    i++;                if(p[i].lor) {                    ans-=p[i].a;                    ans+=p[i].b;                }                else {                    ans-=p[i].c;                    ans+=p[i].a;                }            }while(p[i+1].i==p[i].i&&p[i+1].lor==p[i].lor);            sum=max(ans,sum);        }        cout<<sum<<endl;    }}
0 0