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

 #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. Go语言string,int,int64 ,float之间类型转换方法

    (1)int转string ? 1 2 s := strconv.Itoa(i) 等价于s := strconv.FormatInt(int64(i), 10) (2)int64转string ? 1 ...

  2. Android 反编译工具

    想必玩安卓的童鞋大多都知道,安卓的APK安装包是可以反编译出源代码的,如果开发人员发布时没有对其混淆等加密处理,反编译出来的代码几乎与真实的源代码一模一样. 想要反编译apk,需要用到apktool. ...

  3. HDU4848 Wow! Such Conquering! —— dfs + 剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4848 题解: 一开始读错题目.以为每个点只能访问一遍.其实只要每个点都有被访问就可以了. 首先是用弗洛 ...

  4. pypi指定下载源

    pip install -i http://pypi.douban.com/simple/ scipy==0.19.0

  5. I.MX6 Surfaceflinger 机制

    /**************************************************************************** * I.MX6 Surfaceflinger ...

  6. 「UVA10298」 Power Strings(KMP

    题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 复制 abcd aaaa ababab . 输出样例#1: 复制 1 4 3 题解 Luogu的题解 这里是对目前 ...

  7. 如何在Flask的构架中传递logger给子模块

    Logger的传递 作为一个新手,如何将主函数的logger传入子模块是一件棘手的事情.某些情况下可以直接将logger作为参数传入子模块的构造函数中,但倘若子模块与主模块存在相互依赖的关系则容易出现 ...

  8. 增加,删除GMS包

    1. device/hiteq/vtab_1050_standard/httek.mk BUILD_GMS:=yes GMS_VARIANT:=mini 2. rm out/target/produc ...

  9. java面试编程题

      [程序1]   题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?   //这是一个菲波拉契数列问 ...

  10. <a href="#">什么意思

    转自:https://zhidao.baidu.com/question/67668291.html <a href="#">是链接到本页,因为你有的时候需要有个链接的 ...