题目要求选择一些花的集合,如果暴力去枚举每种选择方法明显是不行的。换种方式考虑:每一个集合都能为最后的答案做出要么正的、要么负的、要么0贡献,先把所有集合能做出的贡献预处理,然后从m个集合里面选择贡献为正的即可。

AC代码:

#include<cstdio>
const int maxn=100+5;
struct node{
	int l,r;
	int ans;
}b[maxn];
int a[maxn];
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(int i=1;i<=n;++i){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<m;++i){
			b[i].ans=0;
			scanf("%d%d",&b[i].l,&b[i].r);
			for(int j=b[i].l;j<=b[i].r;++j)
				b[i].ans+=a[j];
		}
		int aa=0;
		for(int i=0;i<m;++i){
			if(b[i].ans>0) aa+=b[i].ans;
		}
		printf("%d\n",aa);
	}
	return 0;
}

如有不当之处欢迎指出!

CodeForces-740B Alyona and flowers的更多相关文章

  1. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  2. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  3. Alyona and flowers

    Alyona and flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  7. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  8. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  9. Codeforces Round #340 Watering Flowers

    题目: http://www.codeforces.com/contest/617/problem/C 自己感觉是挺有新意的一个题目, 乍一看挺难得(= =). 其实比较容易想到的一个笨办法就是:分别 ...

  10. codeforces 682C Alyona and the Tree(DFS)

    题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...

随机推荐

  1. Java并发编程的艺术读书笔记(1)-并发编程的挑战

    title: Java并发编程的艺术读书笔记(1)-并发编程的挑战 date: 2017-05-03 23:28:45 tags: ['多线程','并发'] categories: 读书笔记 --- ...

  2. Linux指令--head,tail

    原文出处:http://www.cnblogs.com/peida/archive/2012/11/06/2756278.html head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头 ...

  3. Servlet--HttpServletResponse的2个操作流的方法

    前面已经说过无数多次了,我们的项目都是基于HTTP协议的一次请求,一次响应.实际编码中,我们在处理完逻辑后一般是跳转到一个页面上,或者用输出流返回json字符串.其实跳转到一个页面往往也就是JSP,J ...

  4. 关于oracle视图小结

    关于oracle的视图小记:一. 视图:就是对SQL语句的封装,使用起来更方便.不易出错 优点: 1.简化数据操作:视图可以简化用户处理数据的方式 2.着重于特定数据:不必要的数据或敏感的数据可以 不 ...

  5. sublime卡顿

    sublime突然卡顿,输入字符要一两秒后才显示出来, 解决方法:首选项--插件控制--禁用插件 Git Gutter

  6. 树莓派用U盘安装系统

    * 需要使用Raspbian / Raspbian Lite或更高版本的2017-04-10版本 *不会SD卡装系统? 1.  先用装好Raspbian系统的SD卡启动 在命令行输入    echo ...

  7. FTP 安装配置

    FTP 安装配置: 一.基础操作 yum install -y ftp yum install -y vsftpd service iptables stop chkconfig iptables o ...

  8. Jmeter之http性能测试实战 非GUI模式压测 NON-GUI模式 结果解析TPS——干货(十一)

    性能测试计划 性能测试用例 录制脚本 性能测试结果 性能测试报告 性能测试监控报告 准备工作 从脚本已录制成功之后开始进行压测 安装Jmeter拓展插件 查看 Transactions per Sec ...

  9. @RequestMapping注解

    Spring MVC中用于参数绑定的注解有很多,都在org.springframework.web.bind.annotation包中,根据它们处理的request的不同内容部分可以分为四类(主要讲解 ...

  10. phantomjs集成到scrapy中,并禁用图片,切换UA

    phantomjs是一个没有界面的浏览器,支持各种web标准,提供DOM 处理, CSS 选择器, JSON, Canvas, 和 SVG,对于爬取一些经过js渲染的页面非常有用.但是phantomj ...