zoukankan      html  css  js  c++  java
  • Lecture Sleep(前缀和)

    Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.

    You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that and will write down all the theorems lecturer tells.

    You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

    Input

    The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.

    The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute.

    The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.

    Output

    Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

    Example
    Input
    Copy
    6 3
    1 3 5 2 5 4
    1 1 0 1 0 0
    Output
    Copy
    16
    Note

    In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.

    题解:我们根据样例输入来分析大意:我现在要去听一个6分钟的讲座,根据样例输入的第三行,我在第1、2、4分钟是醒着的,其他时间睡着了。其中有一种清醒手段能让我连续三分钟保持清醒(样例输入第一行第二个),例如在第1、2、3分钟使用这个手段,那么将改变我在第3分钟的状态(本来是0,代表睡着,现在由于使用了手段,于是醒了)。样例输入的第二行代表每分钟讲座会讲多少个数学定理,在醒着的时候我可以将定理全部记下来,然而在睡着的时候我无法记笔记。现在要求计算我最多能记多少笔记(在使用清醒手段的情况下)。

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stack>
     4 #include<string.h>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<map>
     8 #include<vector>
     9 #define PI acos(-1.0)
    10 using namespace std;
    11 typedef long long ll;
    12 #define Inf 0x3f3f3f3f
    13 int m,n;
    14 int str[100001];
    15 int visit[505000];
    16 int k[50001];
    17 int dp[550000];
    18 int di[4][2]= {{-1,0},{1,0},{0,-1},{0,1}};
    19 map<ll,ll>::iterator it;
    20 int main()
    21 {
    22     int i,j;
    23     scanf("%d%d",&m,&n);
    24     memset(dp,0,sizeof(dp));
    25     memset(k,0,sizeof(k));
    26     for(i=1; i<=m; i++)
    27     {
    28         scanf("%d",&str[i]);
    29         dp[i]=dp[i-1]+str[i];//记录前n项和
    30     }
    31     int ans=-1,p=-1,kk=0;
    32     for(i=1; i<=m; i++)
    33     {
    34         scanf("%d",&visit[i]);
    35         if(visit[i])
    36             kk=str[i];
    37         else
    38             kk=0;
    39         k[i]=k[i-1]+kk;//记录非零前n项和
    40     }
    41     int sum=0,ans1;
    42     for(i=1; i<=m-n+1; i++)
    43     {
    44         ans1=dp[i+n-1]-dp[i-1]+sum+k[m]-k[i+n-1]+k[i-1];//枚举每一种情况(再第i分钟所获得的最大定理数)
    45         ans=max(ans,ans1);
    46     }
    47     printf("%d
    ",ans);
    48     return 0;
    49 }
  • 相关阅读:
    eclipse两种注释的快捷键
    为什么我的安卓虚拟机没有虚拟键盘
    windows server2012部署apache项目访问后台管理系统时tomcat就停了是怎么回事
    什么时候你可以考虑离职?遇到这6种情况
    安装wampserver后,在www文件夹下面写php文件,而在网页里输入localhost而无法打开php文件时解决办法汇总
    访问localhost文件下的testmysql.php文件报Not Found
    访问localhost的phpmyadmin出现访问被拒绝
    wamp如何设置数据库的密码
    WAMP不能启动, 一直处于红色图标或者橙色图标的解决办法
    [AngularJS] Decorator a directive
  • 原文地址:https://www.cnblogs.com/moomcake/p/9211908.html
Copyright © 2011-2022 走看看