博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj--3061--Subsequence(贪心)
阅读量:5337 次
发布时间:2019-06-15

本文共 1378 字,大约阅读时间需要 4 分钟。

Subsequence
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10882   Accepted: 4498

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

210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5

Sample Output

23

Source

简直就是超时专题,还是自己太傻了,想着暴力可以的,

#include
#include
#include
using namespace std;int num[100000+10];int main(){ int t; scanf("%d",&t); while(t--) { int n,ans; scanf("%d%d",&n,&ans); memset(num,0,sizeof(num)); for(int i=0;i
=ans) { f=true; minn=min(minn,r-l); sum-=num[l++]; } } if(f) printf("%d\n",minn); else printf("0\n"); } return 0;}

转载于:https://www.cnblogs.com/playboy307/p/5273433.html

你可能感兴趣的文章
关于这次软件以及pda终端的培训
查看>>
jQuery上传插件Uploadify 3.2在.NET下的详细例子
查看>>
如何辨别一个程序员的水平高低?是靠发量吗?
查看>>
新手村之循环!循环!循环!
查看>>
正则表达式的用法
查看>>
线程安全问题
查看>>
SSM集成activiti6.0错误集锦(一)
查看>>
下拉刷新
查看>>
linux的子进程调用exec( )系列函数
查看>>
MSChart的研究
查看>>
C# 索引器
查看>>
MySQLdb & pymsql
查看>>
zju 2744 回文字符 hdu 1544
查看>>
delphi 内嵌汇编例子
查看>>
【luogu P2298 Mzc和男家丁的游戏】 题解
查看>>
前端笔记-bom
查看>>
MATLAB作图方法与技巧(一)
查看>>
上海淮海中路上苹果旗舰店门口欲砸一台IMAC电脑维权
查看>>
Google透露Android Market恶意程序扫描服务
查看>>
给mysql数据库字段值拼接前缀或后缀。 concat()函数
查看>>