麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

尺取法

2019-11-11 05:12:07
字體:
來源:轉載
供稿:網友

例題:POJ 3061


Subsequence

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13348 Accepted: 5635

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

Southeastern Europe 2006


#include<iostream>#include<cstdio>#define min(a,b) (a<b?a:b)#define max(a,b) (a>b?a:b)using namespace std;const int MAXN=1e5;int N,S;int a[MAXN+1];int num;void solve(){ int res=N+1; int s=0,t=0,sum=0; while(true) { while(t<N&&sum<S) sum+=a[t++]; if(sum<S) break; res=min(res,t-s); sum-=a[s++]; } if(res>N) res=0; cout<<res<<endl;}int main(){ cin>>num; for(int tmp=1;tmp<=num;tmp++) { int i=1; cin>>N>>S; for(i=1;i<=N;i++) cin>>a[i]; solve(); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品视频自拍 | 91热久久免费频精品黑人99 | 久久久涩 | 国产成人在线一区 | 国产精品久久久久久久久久尿 | 欧美日韩在线播放一区 | 偷偷草网站 | 欧美日日操 | 精品国产一区二区在线观看 | 国产精品久久久久久影视 | 99精品视频在线观看免费 | 亚洲天堂中文字幕在线观看 | 国产精选电影免费在线观看网站 | 日本不卡一区二区三区在线 | 91网页视频入口在线观看 | 欧美大穴 | 国产午夜精品一区二区三区免费 | 精品久久久久久久久久久久久 | 久啪视频| 亚洲精品一二三区 | 一区二区久久电影 | 国产69精品久久久久9999不卡免费 | 国产又白又嫩又紧又爽18p | 日日草夜夜操 | 99在线热播精品免费 | japanese javhd | 国产99久久久久久免费看 | 久久精品影视 | 免费观看黄色片视频 | 视频www| 欧美a级大胆视频 | 污视频在线免费播放 | 国产91丝袜在线播放 | av影院在线播放 | 亚洲精品成人18久久久久 | 国产精品免费一区二区三区四区 | 久久久无码精品亚洲日韩按摩 | 国产精品啪一品二区三区粉嫩 | 国产精品二区高清在线 | 成人福利视频在线 | 国产a一级片 |