首页 > 其他 > 详细

FZU2013 short problem

时间:2015-07-15 22:25:16      阅读:253      评论:0      收藏:0      [点我收藏+]

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\n", ans);
    }
    return 0;
}

  

 

FZU2013 short problem

原文:http://www.cnblogs.com/zero-begin/p/4649572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!