Subsequence
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14709   Accepted: 6210

Description

A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum
of which is greater than or equal to S.

Input

The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The
input will finish with the end of file.

Output

For each the case the program has to print the result on separate line of the output file.if no answer, print 0.

Sample Input

2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5

Sample Output

2
3

Source


—————————————————————————————————————
题目的意思是给出n个整数,求区间和大于等于m的最小区间长度
思路:由于和具有单调性,直接尺取法
#include <iostream>
#include <functional>
#include <stdio.h>
#include <queue>
#include<cmath>
#include<algorithm>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f;
int n,m;
int a[1000005];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int l=0,r=0;
int sum=0;
int ans=inf;
while(1)
{
while(r<n&&sum<m)
{
sum+=a[r++];
}
if(sum<m) break;
ans=min(ans,r-l);
sum-=a[l++];
}
if(ans==inf)
ans=0;
printf("%d\n",ans);
}
return 0;
}


POJ2061 Subsequence 2017-05-25 19:49 83人阅读 评论(0) 收藏的更多相关文章

  1. 利用Python分析GP服务运行结果的输出路径 & 实现服务输出路径的本地化 分类: Python ArcGIS for desktop ArcGIS for server 2015-08-06 19:49 3人阅读 评论(0) 收藏

    最近,一直纠结一个问题:做好的GP模型或者脚本在本地运行,一切正常:发布为GP服务以后时而可以运行成功,而更多的是运行失败,甚至不能知晓运行成功后的结果输出在哪里. 铺天盖地的文档告诉我,如下信息: ...

  2. HDU1233 还是畅通工程 2017-04-12 19:49 64人阅读 评论(0) 收藏

    还是畅通工程 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  3. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

  4. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  5. Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏

    Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...

  6. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  7. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

  8. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  9. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

随机推荐

  1. Oracle_高级功能(4) 数据库存储结构

    数据库存储结构分为:物理存储结构和逻辑存储结构.物理结构和逻辑结构分开,对物理数据的存储不会影响对逻辑结构的访问.1.物理存储结构 数据库文件 os block2.逻辑存储结构 tablespace ...

  2. js的面向对象

    JavaScript不区分类和实例的概念,而是通过原型(prototype)来实现面向对象编程. 原型是指当我们想要创建xiaoming这个具体的学生时,我们并没有一个Student类型可用 var ...

  3. 探索未知种族之osg类生物---呼吸分解之advance

    回顾 我们用了两节的内容才堪堪讲解完ViewerBase::frame()函数中调用的realize()---Viewer:: realize()函数.我们简单的总结就是Viewer:: realiz ...

  4. [转] initrd详解

    转自:http://www.cnblogs.com/leaven/archive/2010/01/07/1641324.html 在Linux操作系统中,有一项特殊的功能——初始化内存盘INITRD( ...

  5. BZOJ1227或洛谷2154 [SDOI2009]虔诚的墓主人

    BZOJ原题链接 洛谷原题链接 又是扫描线,题解可看大佬的博客(太懒了不想打) #include<cstdio> #include<algorithm> using names ...

  6. mysql 8小时timeout问题

    MySQL> show variables like '%timeout%'; +--------------------------+-------+ | Variable_name      ...

  7. swift 中使用weak self

    request.responseString(encoding: NSUTF8StringEncoding) {[weak self] (res) -> Void in if let stron ...

  8. c sharp multithreading

    1.  静态方法 using System; using System.Threading; namespace PlusThread { class Program { static void Ma ...

  9. 实现SQL express版做自动备份数据库的方法

    SQL Server 2005/2008 Express版没有代理组件,不支持维护计划.可以采用下面的办法实现每日备份: 一.在要备份的数据库中创建存储过程. 存储过程名称:sp_BackupData ...

  10. idea maven 创建webapp项目没有src目录

    archetypeCatalog=internal