Lotus and Horticulture
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 549 Accepted Submission(s): 177
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
Recommend
jiangzijing2015 | We have carefully selected several similar problems for you:
6014
6013
6012
6011
6010
题意:给n个植物,适宜生长的温度范围是l~r,适宜温度可获得的研究价值为a,高于适宜温度可获得研究价值为b,低于则c,问可获得的最大研究价值是多少。温度只能取整数。
思路:因为是闭区间,故我们先将左端点和右端点+0.5离散化,因为0.5很难处理,故*2就好了,假设一开始取温度为无穷小,则答案为∑c,然后每经过一个左端点,研究价值+a-c,每经过右端点+0.5,研究价值+b-a,故只需要扫一遍记录最大值就好了,但因为温度只能取整数,所以还需要一点小小的处理,详细看代码吧。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<functional>
typedef long long LL;
using namespace std;
#define maxn 100005
#define ll l,mid,now<<1
#define rr mid+1,r,now<<1|1
#define lson l1,mid,l2,r2,now<<1
#define rson mid+1,r1,l2,r2,now<<1|1
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
struct node{
int value, pos;
}p[maxn];
bool cmp(node a, node b){
return a.pos < b.pos;
}
int main(){
int t;
scanf("%d", &t);
while (t--){
int n;
scanf("%d", &n);
int len = 0;
LL ans = 0;
while (n--){
int l, r, a, b, c;
scanf("%d%d%d%d%d", &l, &r, &a, &b, &c);
ans += c;
p[len].pos = l << 1;
p[len++].value = a - c;
p[len].pos = r << 1 | 1;
p[len++].value = b - a;
}
sort(p, p + len, cmp);
LL maxnum = ans;
for (int i = 0; i < len; i++){
ans += p[i].value;
while (p[i + 1].pos == p[i].pos){
ans += p[++i].value;
}
maxnum = max(maxnum, ans);
}
printf("%lld\n", maxnum);
}
}