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

 #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. 20170313 ABAP程序未激活状态下保存或激活进入debug

    自动进入断点,没有设置的.FUNCTION RS_NEW_PROGRAM_INDEX. https://archive.sap.com/discussions/message/14132983 解决办 ...

  2. ubuntu搭建nginx

    1.下载nginx压缩包 2.上传.解压 tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 3.安装 make  install 4.启动,停止 ,重启 服务 可 ...

  3. Struts多个文件上传

    Struts2多个文件上传 10级学员 韩晓爽课堂笔记 多个文件上传分为List集合和数组,下面我们着重介绍一下list集合的上传.都大同小异. 一 介绍 1. 在struts2文件上传的时候要先导入 ...

  4. 关于web页自动适配屏幕大小

    一.先了解下html5的viewport使用 随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的 ...

  5. HDU2896 病毒侵袭 —— AC自动机

    题目链接:https://vjudge.net/problem/HDU-2896 病毒侵袭 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  6. 骨牌覆盖问题 KxM

    前面我们说了一些简单的骨牌覆盖问题,有了上面的经验,我们可以尝试解决K*M的 思路和上一篇文章所提到的3*N的 很类似: 依然是矩阵快速幂.我们需要把一个小的边固定下来作为的已知边,然后进行矩阵快速幂 ...

  7. PIL 安装及使用

    我ubunto虚拟机自带的是python2.7,好像PIL也只支持到2.7. PIL包的安装 Debian/Ubunto Linux下直接安装: sudo apt-get install python ...

  8. C# 获取QQ好友列表信息的实现

    分析部分 当我们访问QQ空间的时候,大家可以在右侧的发现一个这样的统计信息  当点击这个链接的时候,会跳转到  这样一个URL 这个URl可以管理好友,当然也就能读取到好友  上面我们是在浏览器中的操 ...

  9. JavaScript-Tool-导向:jquery.steps-un

    ylbtech-JavaScript-Tool-导向:jquery.steps 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. http://www.jqu ...

  10. calico在docker上的部署及验证

    1. 背景 以下的部署以五台服务器环境为例: 服务器1: hostname为etcdnode1, IP为192.168.56.100 服务器2: hostname为etcdnode2, IP为192. ...