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

  

时间: 2025-01-14 18:55:25

FZU2013 short problem的相关文章

HDU 4291 A Short problem(矩阵+循环节)

A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2711    Accepted Submission(s): 951 Problem Description According to a research, VIM users tend to have shorter fingers, compared

贪心 FZU 2013 A short problem

题目传送门 1 /* 2 题意:取长度不小于m的序列使得和最大 3 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 1e6 + 10; 10 const int INF = 0x3f3f3f3f; 11 int a[MAXN], sum[MAXN]; 12 13 in

HDU----(4291)A Short problem(快速矩阵幂)

A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1716    Accepted Submission(s): 631 Problem Description According to a research, VIM users tend to have shorter fingers, compared

HDU——4291A Short problem(矩阵快速幂+循环节)

A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2461    Accepted Submission(s): 864 Problem Description According to a research, VIM users tend to have shorter fingers, compared

hdu 4291 A Short problem(矩阵+取模循环节)

A Short problem                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1785    Accepted Submission(s): 651 Problem Description According to a r

HDU 4291 A Short problem

A Short problem Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 429164-bit integer IO format: %I64d      Java class name: Main According to a research, VIM users tend to have shorter fingers, compared with Em

HDU 4291 A Short problem (2012成都网络赛,矩阵快速幂+循环节)

链接: click here~~ 题意: According to a research, VIM users tend to have shorter fingers, compared with Emacs users. Hence they prefer problems short, too. Here is a short one: Given n (1 <= n <= 1018), You should solve for g(g(g(n))) mod 109 + 7 where

HDU 4291 A Short problem 短问题 (递推,微变型)

题意:给出递推式 g(n) = 3g(n - 1) + g(n - 2),且g(1) = 1,g(0) = 0.求g( g( g(n))) mod 109 + 7. 思路:要求的g( g( g(n)))一共里外3层.看到时间限制1s,数据最大10^18,必定不能老实递推,要么有循环,要么用通项公式.这里用通项公式太麻烦了,数字不好算,而g(n)%109 + 7是有规律的, 在n=222222224之后会出现循环,也就是n=0和n=222222224的g(n)是一样的,这是最外层.那么也就是说在g

HDU 4291 A Short problem 又是一道神奇的矩阵

首先要知道一个姿势,对于Fib数列这类的东西,只要取余就一定会出现循环节.所以上来就直接暴力打表找规律就好了. MOD = 1000000007 发现循环节是 222222224. MOD = 2222222227 发现循环节是 183120 然后这个问题就解决了. 不要问我为啥会出现循环节,我也不会证明... ----------------------------------分割线---------------------------------- 我好像会证明了,试着证一发. 设有一个递推