[CC-MCHEF]MasterChef
[CC-MCHEF]MasterChef
题目大意:
\(n(n\le10^5)\)片花,第\(i\)片花的美观度为\(b_i(|b_i|\le10^9)\)。总体美观度为各片花的美观度之和。
由于有些花太丑了,要把它们除掉。有\(m\)位工人,第\(i\)位工人只会除编号在\(l_i\)和\(r_i\)之间的花,且每除一片花,收费\(c_i\)元。总共有\(k\)元的资金预算,问工人除完花后,总体美观度最大是多少。
思路:
首先计算不除掉的答案。
线段树求区间最小值以后可以得到移除每个花的代价,然后背包就行了。
时间复杂度\(\mathcal O(n\log n+nk)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
register char ch;
register bool neg=false;
while(!isdigit(ch=getchar())) neg|=ch=='-';
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return neg?-x:x;
}
typedef long long int64;
const int N=1e5+1,K=501;
int b[N];
int64 f[K];
class SegmentTree {
#define _left <<1
#define _right <<1|1
#define mid ((b+e)>>1)
private:
int val[N<<2];
public:
void build(const int &p,const int &b,const int &e) {
val[p]=INT_MAX;
if(b==e) return;
build(p _left,b,mid);
build(p _right,mid+1,e);
}
void modify(const int &p,const int &b,const int &e,const int &l,const int &r,const int &x) {
if(b==l&&e==r) {
val[p]=std::min(val[p],x);
return;
}
if(l<=mid) modify(p _left,b,mid,l,std::min(mid,r),x);
if(r>mid) modify(p _right,mid+1,e,std::max(mid+1,l),r,x);
}
int query(const int &p,const int &b,const int &e,const int &x) const {
int ret=val[p];
if(b==e) return ret;
if(x<=mid) ret=std::min(ret,query(p _left,b,mid,x));
if(x>mid) ret=std::min(ret,query(p _right,mid+1,e,x));
return ret;
}
#undef _left
#undef _right
#undef mid
};
SegmentTree t;
int main() {
for(register int T=getint();T;T--) {
const int n=getint(),k=getint(),m=getint();
std::fill(&f[0],&f[k]+1,0);
int64 ans=0;
for(register int i=1;i<=n;i++) {
b[i]=getint();
ans+=b[i];
}
t.build(1,1,n);
for(register int i=0;i<m;i++) {
const int l=getint(),r=getint(),c=getint();
t.modify(1,1,n,l,r,c);
}
for(register int i=1;i<=n;i++) {
if(b[i]>=0) continue;
const int c=t.query(1,1,n,i);
for(register int j=k;j>=c;j--) {
f[j]=std::max(f[j],f[j-c]-b[i]);
}
}
printf("%lld\n",ans+f[k]);
}
return 0;
}
[CC-MCHEF]MasterChef的更多相关文章
- Atitti.dw cc 2015 绿色版本安装总结
Atitti.dw cc 2015 绿色版本安装总结 1.1. 安装程序无法初始化.请下载adobe Support Advisor检测该问题.1 1.1.1. Adobe Application M ...
- 【Hello CC.NET】CC.NET 实现自动化集成
一.背景 公司的某一金融项目包含 12 个子系统,新需求一般按分支来开发,测完后合并到主干发布.开发团队需要同时维护开发环境.测试环境.模拟环境(主干).目前面临最大的两个问题: 1.子系统太多,每次 ...
- 浅谈iptables防SYN Flood攻击和CC攻击
------------------------本文为自己实践所总结,概念性的东西不全,这里粗劣提下而已,网上很多,本文主要说下目前较流行的syn洪水攻击和cc攻击------------------ ...
- checking for fcc ....no checking for cc .. no
源码编译,提示缺少gcc cc cl.exe 解决方案: yum install -y gcc glibc
- 编译器 cc、gcc、g++、CC 的区别
gcc 是GNU Compiler Collection,原名为Gun C语言编译器,因为它原本只能处理C语言,但gcc很快地扩展,包含很多编译器(C.C++.Objective-C.Ada.Fort ...
- [CC]区域生长算法——点云分割
基于CC写的插件,利用PCL中算法实现: void qLxPluginPCL::doRegionGrowing() { assert(m_app); if (!m_app) return; const ...
- [CC]点云密度计算
包括两种计算方法:精确计算和近似计算(思考:local density=单位面积的点数 vs local density =1/单个点所占的面积) 每种方法可以实现三种模式的点云密度计算,CC里面的 ...
- 【日常小记】统计后缀名为.cc、.c、.h的文件数【转】
转自:http://www.cnblogs.com/skynet/archive/2011/03/29/1998970.html 在项目开发时,有时候想知道源码文件中有多少后缀名为.cc..c..h的 ...
- error: command 'cc' failed with exit status 1
报错: Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/ ...
- 基于日志数据分析以防御CC攻击的想法
1. What - 什么是CC攻击 CC攻击,即针对应用层HTTP协议的DDos攻击,攻击者在短时间内向目标服务器发送大量的HTTP请求,使得服务器会非常繁忙,资源消耗会增加:同时,如果请求中包含基于 ...
随机推荐
- OGG-01389 File header failed to parse tokens.
http://blog.csdn.net/zbdba/article/details/44095105; 处理的思路: 1.查看日志 2.在目标端看最新的队列文件的日期,假如没有最新的队列文件就说明源 ...
- SQLServer数据操作(建库、建表以及数据的增删查改)[转]
SQLSever数据操作 一.建立数据库: create database DB ---数据库名称 ( name=data1 --文件名, filename ...
- TCP检验和
TCP的检验和 检验和目的 目的是为了发现TCP首部和数据在发送端到接收端之间发生的任何改动.如果接收方检测到检验和有差错,则TCP段会被直接丢弃. TCP在计算检验和时,要加上一个12字节的伪首 ...
- Nagios Openstack Plugin
Some simple example for checking Openstack services check nova service list #!/bin/sh export OS_PROJ ...
- python网络编程--RabbitMQ
一:RabbitMQ介绍 RabbitMQ是AMPQ(高级消息协议队列)的标准实现.也就是说是一种消息队列. 二:RabbitMQ和线程进程queue区别 线程queue:不能跨进程,只能用于多个线程 ...
- java基础24 线程、多线程及线程的生命周期(Thread)
1.1.进程 正在执行的程序称作为一个进程.进程负责了内存空间的划分 疑问1:windows电脑称之为多任务的操作系统,那么Windows是同时运行多个应用程序呢? 从宏观的角度:windows确实在 ...
- SCTP客户端与服务器
/** * @brief - Send a message, using advanced SCTP features * The sctp_sendmsg() function allows you ...
- Linux学习笔记:vi常用命令
在Linux系统中常用vi命令进行文本编辑. vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器.Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved), ...
- Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据
Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据 */--> div.org-src-container { font-size: 85%; font-fam ...
- sdoi2014-向量集-线段树-二分斜率
注意到线段树一个节点只有满了才会被用到,那时再建ConvexHull就行了... #include <bits/stdc++.h> using namespace std; namespa ...