ZCMU训练赛-J(循环节+字符串处理)

J - Java Beans

 

There are N little kids sitting in a circle, each of them are carrying some java beans in their hand. Their teacher want to select M kids who seated in M consecutive 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 from Mconsecutively seated kids. Can you help her?

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases.

For each test case, the first line contains two integers N (1 ≤ N ≤ 200) and M (1 ≤ M ≤ N). Here N and M are defined in above description. The second line of each test case contains Nintegers Ci (1 ≤ Ci ≤ 1000) indicating number of java beans the ith kid have.

Output

For each test case, output the corresponding maximum java beans the teacher can collect.

Sample Input

2
5 2
7 3 1 3 9
6 6
13 28 12 10 20 75

Sample Output

16
158
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <set>
 8 #include <queue>
 9 #include <stack>
10 #include <map>
11 #include <vector>
12 using namespace std;
13 typedef long long ll;
14 typedef unsigned long long ull;
15 typedef pair<int, int> P;
16 int a[200];
17 bool cmp(const int &a,const int &b)
18 {
19     return a>b;
20 }
21 int main()
22 {
23     int t;
24     int n,m,i,j,k;
25     int a[205];
26     scanf("%d",&t);
27     while(t--)
28     {
29         int b[205]={0};
30         scanf("%d%d",&n,&m);
31         for(i=0;i<n;i++)
32             scanf("%d",&a[i]);
33 
34         for(i=0;i<n;i++)
35         {
36             for(j=i,k=0;j<n+1,k<m;j++,k++)
37             {
38                 if(j==n)
39                     j=0;
40                     b[i]+=a[j];
41             }
42         }
43         sort(b,b+n);
44        printf("%d\n",b[n-1]);
45     }
46     return 0;
47 }
View Code

 

#include<stdio.h>
int d[210];
int main(int argc, char* argv[])
{
    int t,i,j;
    int n,m,sum,max;
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
            scanf("%d%d",&n,&m);
            for(i=0;i<n;i++)
            scanf("%d",&d[i]);
            
            max=0;
            for(i=0;i<n;i++)
            {
                sum=0;//注意复位
                for(j=i;j<i+m;j++)
                sum+=d[j%n];
                if(max<sum)
                    max=sum;
            }
            printf("%d\n",max);
        }
    }
    return 0;
}
View Code

 

全部评论

相关推荐

03-26 13:04
已编辑
电子科技大学 算法工程师
xiaowl:你这个简历“条目上”都比较有深度性,但是实际上面试官又没法很好的评估你是怎么达到很多看上去很厉害的结果的。要避免一些看上去很厉害的包装,比如高效的内存复用策略的表达,如果仅是简单的一些内存共享机制,而且面试上也没有深挖的空间,就不要这样表达。比如,工程化模式本质上可能就是定义了一些abstract class,那也就没特别多值得讲的内容。建议简历上应该侧重那些你花了大量时间和精力解决、研究的问题,不要过分追求“丰富”,而是关注在技术深入度、问题解决能力的表现上。
没有实习经历,还有机会进...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务