Codeforces 740 B Alyona and flowers(前缀和)
来源:互联网 发布:海美迪q5四核 优化补丁 编辑:程序博客网 时间:2024/06/12 00:00
题目地址:http://codeforces.com/contest/740/problem/B
题意:我也看不懂,太长了,看别人博客发现就是求给定区间和的最大值(某些区间可以不选)
思路:求前缀和,然后计算每个区间和,如果和>0的话就加上。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define LL long long #define N 110#define M 50010#define inf 0x3f3f3f3f3f3f3f3fusing namespace std;const LL mod = 1e9 + 7;const double eps = 1e-9;int main() { cin.sync_with_stdio(false); int n, m; int a, b, c; int num[N]; while (cin >> n >> m) { num[0] = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; num[i] += num[i - 1]; } int sum = 0; for (int i = 0; i < m; i++) { cin >> a >> b; c = num[b] - num[a - 1]; if (c > 0) { sum += c; } } cout << sum << endl; } return 0;}
阅读全文
0 0
- Codeforces 740 B Alyona and flowers(前缀和)
- 【81.82%】【codeforces 740B】Alyona and flowers
- Codeforces 740B Alyona and flowers
- CodeForces 740B - Alyona and flowers(贪心)
- 740B Alyona and flowers codeforces
- codeforces 740B Alyona and flowers
- CodeForces-740B Alyona and flowers
- CodeForces 740B Alyona and flowers 简单暴力
- B. Alyona and flowers
- Codeforces#381(Div. 2) B.Alyona and flowers【思维+暴力】
- Codeforces Round #381 (Div. 2) B. Alyona and flowers
- Codeforces Round #209 (Div. 2) B. Alyona and flowers
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(思维题目)
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(贪心 模拟)
- Codeforces740B. Alyona and flowers
- Codeforces 816B Karen and Coffee(前缀和)
- codeforces 816-B. Karen and Coffee(前缀和+思维)
- 【CODEFORCES】 B. Pashmak and Flowers
- Android Eclipse+ADT+SDK+NDK+OpenGL在Ubuntu进行安卓纯C/C++开发实现
- Linux学习——shell编程之环境变量配置文件
- 遍历Map的四种常见方法
- HDU 1166 线段树 解题报告
- 如何限制程序互斥运行?
- Codeforces 740 B Alyona and flowers(前缀和)
- Python编程_Lesson007_循环讲解和函数
- jzoj. 1300. 卫星照片
- 644. Maximum Average Subarray II
- 树链剖分学习笔记
- SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
- LeetCode 636 : Exclusive Time of Functions(python)
- webstorm 激活 2017.7.16测试可用
- 单例模式(Singleton Pattern)。