国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

HDU 6012

2019-11-14 12:02:15
字體:
供稿:網(wǎng)友

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

貪心即可,假設(shè)溫度從負(fù)無窮大開始遞增,于是首先算出所有植物C情況之和,然后對(duì)每個(gè)點(diǎn)進(jìn)行排序,如果是L點(diǎn),則-C+A,如果是R點(diǎn),則-A+B,同時(shí)有兩點(diǎn)要注意:1,值相同的點(diǎn)。2.值相同時(shí)L,R不同怎么處理,在排序時(shí)應(yīng)先對(duì)值排序,如果值相同的情況下,要優(yōu)先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; }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 得荣县| 寿阳县| 社旗县| 岗巴县| 沐川县| 凤山县| 葫芦岛市| 卢龙县| 石嘴山市| 九江县| 晋宁县| 汾西县| 丽水市| 庆安县| 鄂托克前旗| 琼结县| 岳阳县| 荥阳市| 罗江县| 大同市| 岑巩县| 仪征市| 屯留县| 惠东县| 鄯善县| 巨鹿县| 邵武市| 封开县| 方城县| 赤水市| 五家渠市| 大同县| 渝中区| 托里县| 莎车县| 茂名市| 文山县| 汪清县| 岳池县| 青海省| 青海省|