前缀后缀和搞一搞,然后枚举一下区间,找出最大值

 #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))的更多相关文章

  1. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

  2. C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))

    //暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...

  3. (模拟)关于进制的瞎搞---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的机器,机器每次只取最低位--% ...

  4. Educational Codeforces Round 41 (Rated for Div. 2)(A~D)

    由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...

  5. Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))

    题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...

  6. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  7. Educational Codeforces Round 41 (Rated for Div. 2)

    这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...

  8. 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 ...

  9. Educational Codeforces Round 78 (Rated for Div. 2)E(构造,DFS)

    DFS,把和当前结点相连的点全都括在当前结点左右区间里,它们的左端点依次++,然后对这些结点进行DFS,优先对左端点更大的进行DFS,这样它右端点会先括起来,和它同层的结点(后DFS的那些)的区间会把 ...

随机推荐

  1. Vue中的计算属性和监听器(computed 与 watch)

    react中数据是单向绑定的,而vue中数据是双向绑定的.为什么? 在react中,主要是通过setState 去改变state的值:而在vue中,会自动的触发set 与get 改变属性的值. 在vu ...

  2. MySQL学习笔记(六)—— MySQL自连接

    有的时候我们需要对同一表中的数据进行多次检索,这个时候我们可以使用之前学习过的子查询,先查询出需要的数据,再进行一次检索. 例如:一张products表,有产品id,供应商id(vend_id),产品 ...

  3. BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口:分治 递归

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1621 题意: 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土 ...

  4. druid.io 海量实时OLAP数据仓库 (翻译+总结) (1)——分析框架如hive或者redshift(MPPDB)、ES等

    介绍 我是NDPmedia公司的大数据OLAP的资深高级工程师, 专注于OLAP领域, 现将一个成熟的可靠的高性能的海量实时OLAP数据仓库介绍给大家: druid.io NDPmedia在2014年 ...

  5. 编译Thrift

    按照 https://syslint.com/blog/tutorial/how-to-install-apache-thrift-on-ubuntu-14-04/ 进行, 编译时出现错误 make[ ...

  6. Struts2 拦截器配置及使用

    在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...

  7. [C++]变量存储类别,指针和引用,类与对象,继承与派生的一些摘要

    C++中共有四种存储类别标识符:auto/static/register/extern 1.auto 函数或分程序内定义的变量(包括形参)可以定义为auto(自动变量).如果不指定存储类别,则隐式定义 ...

  8. android性能测试工具

    Android性能测试工具Emmagee介绍   Emmagee介绍 Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资源的性能测试小工具.该工具的优势在于如同windows系 ...

  9. docker学习 (三) Windows 10 安装Docker

    Docker CE: 社区版,免费. Docker EE: 企业版,收费. 安装:             Windows 10 Pro 64, 必须开启Hyper-v 下载:Docker for W ...

  10. 用于生成交易统计时间戳(常配合echarts走势图使用)

    <?php //获取交易统计时间戳 时间段内每小时 public function getPayCountTimeHours($start_date,$end_date){ $data = ar ...