B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))
前缀后缀和搞一搞,然后枚举一下区间,找出最大值
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = 1e5 + ;
int a[maxn], f[maxn], b[maxn], c[maxn]; int main()
{
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = ; i <= n; i++)
cin >> a[i];
for (int i = ; i <= n; i++)
cin >> f[i];
//前缀和
for (int i = ; i <= n; i++)
if (f[i])b[i] = b[i - ] + a[i];
else b[i] = b[i - ];
//后缀和
for (int i = n; i>; i--)
if (f[i])c[i] = c[i + ] + a[i];
else c[i] = c[i + ]; long long s = ;
for (int i = ; i <= k; i++)s += a[i];
long long ans = ;
for (int i = k; i <= n; i++){
ans = max(b[i - k] + s + c[i + ], ans);
s = s - a[i - k + ] + a[i + ];
}
cout << ans <<endl;
//system("pause");
return ;
}
B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))的更多相关文章
- D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))
#include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...
- C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))
//暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...
- (模拟)关于进制的瞎搞---You Are Given a Decimal String...(Educational Codeforces Round 70 (Rated for Div. 2))
题目链接:https://codeforc.es/contest/1202/problem/B 题意: 给你一串数,问你插入最少多少数可以使x-y型机器(每次+x或+y的机器,机器每次只取最低位--% ...
- Educational Codeforces Round 41 (Rated for Div. 2)(A~D)
由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...
- Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))
题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Educational Codeforces Round 41 (Rated for Div. 2)
这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...
- Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)
D. Pair Of Lines time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 78 (Rated for Div. 2)E(构造,DFS)
DFS,把和当前结点相连的点全都括在当前结点左右区间里,它们的左端点依次++,然后对这些结点进行DFS,优先对左端点更大的进行DFS,这样它右端点会先括起来,和它同层的结点(后DFS的那些)的区间会把 ...
随机推荐
- 火狐浏览器使用firebug获取xpath和css path
工作中,常常会用到网页元素的定位方式,常用的有xpath和css path两种定位方式. 现在简单介绍如何使用工具自动生成元素的定位字符串. 首先介绍在火狐浏览器上使用FireBug及其扩展FireP ...
- iOS反射机制:objc_property_t的使用
#import <objc/runtime.h> 需要导入这个头文件. 动态获取一个自定义类对象中的所有属性 - (NSDictionary *)allProperties { NSMut ...
- bzoj5259: [Cerc2017]区间
还是很强的一个题 ORZ肉丝哥哥 对于两个相交区间,假如他们两个都是可行的,那么他们的交也可行,不然没可能两边都把它缺的补上 那么对于答案区间,向右找到第一个可行区间右端点覆盖询问区间,就是最优的 考 ...
- ansible-playbook初始化服务器
hosts ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [test] 0.0.0.0 ansible_ssh_us ...
- html5--4-2 video元素的属性
html5--4-2 video元素的属性 学习要点 掌握video元素的基本用法 直到现在,在网页中的大多数视频是通过插件(比如 Flash)来显示的.然而,并非所有浏览器都拥有同样的插件.HTML ...
- hdu 1711 Number Sequence(kmp找子串第一次出现的位置)
题意:裸kmp 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string.h> using nam ...
- 使用MongoDB.NET 2.2.4驱动版本对 Mongodb3.3数据库中GridFS增删改查
Program.cs代码如下: internal class Program { private static void Main(string[] args) { GridFSHelper help ...
- 简单快捷地测试 JPush API
随着 JPush API v3版本的推出,加上之前开放的 Report API,JPush API 逐渐切换为比较好的符合 REST API 的规范,从而也很容易地使用一般的 HTTP/REST 工具 ...
- 使用openssl的aes各种加密算法
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/sta ...
- distutils 打包setup.py
from distutils.core import setup setup(name='hello', version='1.0', description='test example', auth ...