Max Sum of Max-K-sub-sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4883    Accepted Submission(s): 1780

Problem Description
Given a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1].

Now your job is to calculate the max sum of a Max-K-sub-sequence. Max-K-sub-sequence means a continuous non-empty sub-sequence which length not exceed K.
 
Input
The first line of the input contains an integer T(1<=T<=100) which means the number of test cases.

Then T lines follow, each line starts with two integers N , K(1<=N<=100000 , 1<=K<=N), then N integers followed(all the integers are between -1000 and 1000).
 
Output
For each test case, you should output a line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the minimum start position, if still more than one , output the minimum length of them.
 
Sample Input
4
6 3
6 -1 2 -6 5 -5
6 4
6 -1 2 -6 5 -5
6 3
-1 2 -6 5 -5 6
6 6
-1 -1 -1 -1 -1 -1
 
Sample Output
7 1 3
7 1 3
7 6 2
-1 1 1

用两种写法弄过,一种调用STL双向队列,一种是直接数组模拟,感觉模拟麻烦点但是耗时很少,双向队列每次都是调用的函数,所以耗时多。

STL双向队列:(734MS)

;
}

用数组模拟双向队列:(187MS)

;
}

HDU--杭电--3415--Max Sum of Max-K-sub-sequence--队列--双向队列的更多相关文章

  1. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  2. 一个人的旅行 HDU杭电2066【dijkstra算法 || SPFA】

    pid=2066">http://acm.hdu.edu.cn/showproblem.php? pid=2066 Problem Description 尽管草儿是个路痴(就是在杭电 ...

  3. find the safest road HDU杭电1596【Dijkstra || SPFA】

    pid=1596">http://acm.hdu.edu.cn/showproblem.php?pid=1596 Problem Description XX星球有非常多城市,每一个城 ...

  4. 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)

    呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...

  5. hdu杭电1856 More is better【并查集】

    Problem Description Mr Wang wants some boys to help him with a project. Because the project is rathe ...

  6. Sum It Up POJ 1564 HDU 杭电1258【DFS】

    Problem Description Given a specified total t and a list of n integers, find all distinct sums using ...

  7. Advanced Fruits HDU杭电1503【LCS的保存】

    Problem Description The company "21st Century Fruits" has specialized in creating new sort ...

  8. 杭电oj_2058——The sum problem(java实现)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 思路:等差数列公式变形:sum = a1 * len + len *(len -1)/2 抽象成 ...

  9. 畅通project再续 HDU杭电1875 【Kruscal算法 || Prim】

    Problem Description 相信大家都听说一个"百岛湖"的地方吧.百岛湖的居民生活在不同的小岛中.当他们想去其它的小岛时都要通过划小船来实现.如今政府决定大力发展百岛湖 ...

  10. 杭电 5053 the Sum of Cube(求区间内的立方和)打表法

    Description A range is given, the begin and the end are both integers. You should sum the cube of al ...

随机推荐

  1. centos 7安装mysql5.5

    首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安 ...

  2. intellij idea 13&14 插件推荐及快速上手建议 (已更新!)

    原文:intellij idea 13&14 插件推荐及快速上手建议 (已更新!) 早些年 在外企的时候,公司用的是intellij idea ,当时也是从eclipse.MyEclipse转 ...

  3. Visual Studio 2015 & C#6.0

      Visual Studio 2015 & C#6.0 试用报告,持续更新.   昨天早上看到了.net开源的消息,我是非常兴奋的,毕竟局限于Windows的.NET经常被人唾弃.VB暂且不 ...

  4. 警惕使用WebClient.DownloadFile(string uri,string filePath)方法

    原文:警惕使用WebClient.DownloadFile(string uri,string filePath)方法 WebClient.DownloadFile(string uri,string ...

  5. cocos2d-x3.0 经常使用绘图方法

    HelloWorldScene.h 例如,下面的代码被添加: protected: void onDraw(const kmMat4 &transform, bool transformUpd ...

  6. 读书笔记—CLR via C#字符串及文本

    前言 这本书这几年零零散散读过两三遍了,作为经典书籍,应该重复读反复读,既然我现在开始写博了,我也准备把以前觉得经典的好书重读细读一遍,并且将笔记整理到博客中,好记性不如烂笔头,同时也在写的过程中也可 ...

  7. EF的四种开发模式

    EF提供了四种开发模式,具体如下:(转载)Code First(New DataBase) :在代码中定义类和映射关系并通过model生成数据库,使用迁移技术更新数据库.Code First(Exis ...

  8. 利用cxfreeze将Python 3.3打包成exe程序

    参考自别人的博文:http://blog.csdn.net/yatere/article/details/6667230 步骤如下: (1) 下载cxfreeze后安装(先得安装python 3.3) ...

  9. 简单的三层asp.net webForm使用Ninject实现Ioc

    简单的三层asp.net webForm使用Ninject实现Ioc 在asp.net webform下使用Ninject的简单过程. 首先建立个项目,如下图,简单三层(PS:UI层要同时引用BLL. ...

  10. MVC使用RDL报表

    MVC使用RDL报表 这次我们来演示MVC3怎么显示RDL报表,坑爹的微软把MVC升级到5都木有良好的支持报表,让MVC在某些领域趋于短板 我们只能通过一些方式来使用rdl报表. Razor视图不支持 ...