zoukankan      html  css  js  c++  java
  • FZU2013 short problem

    Problem Description

    The description of this problem is very short. Now give you a string(length N), and ask you the max sum of the substring which the length can't small than M.

     Input

    The first line is one integer T(T≤20) indicates the number of the test cases. Then for every case, the first line is two integer N(1≤N≤1000000) and M(1≤M≤N).

    Then one line contains N integer indicate the number. All the number is between -10000 and 10000.

     Output

    Output one line with an integer.

     Sample Input

    2 5 1 1 -2 -2 -2 1 5 2 1 -2 -2 -2 1

     Sample Output

    1 -1

     Source

    FOJ有奖月赛-2011年03月
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<string>
    #include<cmath>
    using namespace std;
    int a[1000010];
    
    int main()
    {
        int n,m;
        int T;
        scanf("%d", &T);
        while(T--){
            scanf("%d%d", &n, &m);
            for(int i = 1; i <= n ; i++)
                scanf("%d", &a[i]);
            for(int i = 1; i <= n ;i++){
                a[i] += a[i-1];
            }
            int t = 0;
            int ans = -1;
            for(int i = m; i <= n ; i++){
                ans = max(ans , a[i] - t);
                t = min(t, a[i-m]);
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    JPA 系列教程1-环境搭建
    微信企业号接收消息(使用SpringMVC)
    oracle xe 数据库用户操作
    eclipse快捷键
    堆和栈的区别(重要)
    synchronized的4种用法
    servlet匹配规则和顺序
    JAVA中的枚举
    JSON对象操作
    Handler
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4649572.html
Copyright © 2011-2022 走看看