a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

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

尺取法

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久久久成人 | 精品日韩视频 | 狠狠夜夜| 青青视频免费 | xxx在线| 十环传奇在线观看完整免费高清 | 色综合天天天天做夜夜夜夜做 | 欧美成人一区二区三区片免费 | 欧美视频一区二区在线 | 欧美自拍视频一区 | 午夜日韩| 久久亚洲成人 | 国产在线h | а天堂中文最新一区二区三区 | 亚洲欧美一区二区三区在线 | 国产精品久久久久影院色老大 | 国产视频大全 | 亚洲男人的天堂网站 | 欧美激情欧美激情在线五月 | 日本a区| 亚洲日韩欧美一区二区在线 | 国产成人一区二区三区 | 亚洲精品免费看 | 99精品久久99久久久久 | 91精品国产欧美一区二区 | 999久久久| 国产亚洲欧美在线 | 天天夜夜操操 | 干中文字幕| 91在线精品秘密一区二区 | 国产精品久久久久久久久久三级 | 麻豆专区一区二区三区四区五区 | 国产午夜精品一区二区三区嫩草 | 亚洲欧美韩国 | 国产综合一区二区 | 精品久久久久久久久久久久久久 | 亚洲欧美日韩在线一区二区 | 中文字幕视频在线 | 成人久久久精品乱码一区二区三区 | 免费av一区二区三区 | 亚洲精品在线视频 |