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
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
int a[];
bool cmp(const int &a,const int &b)
{
return a>b;
}
int main()
{
int t;
int n,m,i,j,k;
int a[];
scanf("%d",&t);
while(t--)
{
int b[]={};
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&a[i]); for(i=;i<n;i++)
{
for(j=i,k=;j<n+,k<m;j++,k++)
{
if(j==n)
j=;
b[i]+=a[j];
}
}
sort(b,b+n);
printf("%d\n",b[n-]);
}
return ;
}
#include<stdio.h>
int d[];
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=;i<n;i++)
scanf("%d",&d[i]); max=;
for(i=;i<n;i++)
{
sum=;//注意复位
for(j=i;j<i+m;j++)
sum+=d[j%n];
if(max<sum)
max=sum;
}
printf("%d\n",max);
}
}
return ;
}

ZCMU训练赛-J(循环节+字符串处理)的更多相关文章

  1. ZCMU训练赛-H(模拟)

    H - Hard to Play   MightyHorse is playing a music game called osu!. After playing for several months ...

  2. ZCMU训练赛-A(模拟)

    A - Applications https://vjudge.net/contest/174208#overview Recently, the ACM/ICPC team of Marjar Un ...

  3. ZCMU训练赛-B(dp/暴力)

    B - Break Standard Weight The balance was the first mass measuring instrument invented. In its tradi ...

  4. hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)

    传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...

  5. poj 2406 Power Strings【字符串+最小循环节的个数】

                                                                                                      Po ...

  6. Uvalive - 3026 Period (kmp求字符串的最小循环节+最大重复次数)

    参考:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html 总结一下,如果对于next数组中的 i, 符合 i % ( i - n ...

  7. KMP解决字符串最小循环节相关问题

    经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个 ...

  8. HDU 3746 (KMP求最小循环节) Cyclic Nacklace

    题意: 给出一个字符串,要求在后面添加最少的字符是的新串是循环的,且至少有两个循环节.输出最少需要添加字符的个数. 分析: 假设所给字符串为p[0...l-1],其长度为l 有这样一个结论: 这个串的 ...

  9. Period(KMP,循环节问题)

    题意: 求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k 分析: i-next[i]恰好是一个循环节 #include <map> #include <set> ...

随机推荐

  1. 【bzoj1412】[ZJOI2009]狼和羊的故事 网络流最小割

    题目描述 “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! Orez的羊狼圈 ...

  2. [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  3. HttpClient测试类请求端和服务端即可能出现乱码的解决

    junit HttpClient 请求端 代码: package com.taotao.httpclient; import java.util.ArrayList; import java.util ...

  4. Python-Jenkins API使用

    一.概述 最近在工作中需要用到在后台代码中触发Jenkins任务的构建,于是想到Jenkins是否有一些已经封装好的API类库提供,用于处理跟Jenkins相关的操作.下面就简单介绍下我的发现. 二. ...

  5. PHP 抽象类,接口,抽象方法,静态方法

    1.Abstract class(抽象类) 抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 抽象类 ...

  6. 精通javascript笔记(智能社)——数字时钟

    JS代码: <script type="text/javascript">    window.onload=function(){ //小于10的数字补零及数字转字符 ...

  7. (转)C/S 与 B/S 区别

    感谢:http://www.cnblogs.com/xiaoshuai/archive/2010/05/25/1743741.html C/S结构,即Client/Server(客户机/服务器)结构, ...

  8. bzoj1499: [NOI2005]瑰丽华尔兹&&codevs1748 单调队列优化dp

    这道题 网上题解还是很多很好的 强烈推荐黄学长 码风真的好看 神犇传送门 学习学习 算是道单调队列优化dp的裸题吧 #include<cstdio> #include<cstring ...

  9. OOP第三次上机

    上机问题 T1 CSet 还是熟悉的CSet,只是多了个构造函数以及收缩空间. T2 SingleTon 单例问题. 用一个指针保存唯一的实例,用户无法在外部直接新建实例,只能使用外部接口(函数),函 ...

  10. bzoj 2064 DP

    这道题可以抽象成两个数列,将一个数列变换为另一个 数列的代价最小 首先我们可以处理出所有的状态代表,对于每个状态 用二进制来表示,代表的是两个数列中的每一项选还是不选 那么答案最多为n1+n2-2,也 ...