博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[JOI2017/2018]美術展
阅读量:7004 次
发布时间:2019-06-27

本文共 692 字,大约阅读时间需要 2 分钟。

[JOI2017/2018]美術展

题目大意:

\(n(n\le5\times10^5)\)个物品,每个物品有两个属性:尺寸\(A_i\)和收益\(B_i\)。从中选取一个子集,总收益为\(\sum B_i-\max\{A_i\}-\min\{A_i\}\)。求总收益最大值。

思路:

将所有物品按照\(A_i\)排序,\(B_i\)前缀和记作\(S_i\)。答案相当于\(\max\{S_i-A_i+A_j-S_{j-1}\}\)。维护\(A_j-S_{j-1}\)前缀\(\max\)即可。

源代码:

#include
#include
#include
typedef long long int64;inline int64 getint() { register char ch; while(!isdigit(ch=getchar())); register int64 x=ch^'0'; while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); return x;}const int N=5e5+1;struct Node { int64 a,b; bool operator < (const Node &rhs) const { return a

转载于:https://www.cnblogs.com/skylee03/p/10144317.html

你可能感兴趣的文章