Zoj3714: Java Beans

Source: Internet
Author: User

There areNLittle kids sitting in a circle, each of them are carrying some java beans in their hand. Their teacher want to selectMKids who seated inMConsecutive
Seats and collect java beans from them.

The teacher knows the number of Java Beans each kids has, now she wants to know the maximum number of Java Beans she can get fromMConsecutively seated kids. Can you help her?

Input

There are multiple test cases. The first line of input is an integerTIndicating the number of test cases.

For each test case, the first line contains two integersN(1 ≤N≤ 200) andM(1 ≤M≤N).
HereNAndMAre defined in above description. The second line of each test case containsNIntegersCi(1
≤Ci≤ 1000) indicating number of Java BeansIthKid have.

Output

For each test case, output the corresponding maximum Java Beans the teacher can collect.

Sample Input
25 27 3 1 3 96 613 28 12 10 20 75
Sample output
16158
 
It is very easy to give n, k, and calculate the maximum sum of N numbers with the length of K, and there is no negative number. Note that these numbers constitute a ring.
Train of Thought: The data is small, and the water passes through
 
#include <stdio.h>#include <string.h>int main(){    int t,n,k,i,j,a[405],sum,MAX;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&k);        for(i=1; i<=n; i++)        {            scanf("%d",&a[i]);            a[n+i] = a[i];        }        MAX = 0;        for(i=1; i<=n; i++)        {            sum = 0;            for(j = i; j<i+k; j++)            {                sum+=a[j];            }            if(sum>MAX)            MAX = sum;        }        printf("%d\n",MAX);    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.