zoukankan      html  css  js  c++  java
  • foj2013

    View Code
    //Problem 2013 A short problem
    /*
    Accept: 158 Submit: 452
    Time Limit: 1000 mSec Memory Limit : 32768 KB
    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
    */
    #include
    "iostream"
    using namespace std;
    const int M=1000005;
    int t,n,m;
    int i,j;
    int a[M];
    int sum[M];
    int f[M];
    int cmp(int a,int b)
    {
    return a>b?a:b;
    }
    int main()
    {
    scanf(
    "%d",&t);
    while(t--)
    {
    scanf(
    "%d %d",&n,&m);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    int i,Max=-0x7fffffff;
    sum[
    0]=0;
    for(i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    f[m
    -1]=sum[m-1];

    for(i=m; i<=n; i++)
    {
    f[i]
    =cmp( f[i-1]+a[i], sum[i]-sum[i-m]);
    if(f[i]>Max) Max=f[i];
    }
    printf(
    "%d\n",Max);
    }
    return 0;
    }
  • 相关阅读:
    Java第一课
    bootstrap之google fonts
    bootstrap之clearfix
    Leetcode题解
    python图片爬虫
    [python / selenium]
    使用python
    python
    python
    python爬虫入门新手向实战
  • 原文地址:https://www.cnblogs.com/FCWORLD/p/2023616.html
Copyright © 2011-2022 走看看