Test instructions
In a sequence of length n, find the shortest length sequence so that it is greater than or equal to s;
Ideas:
pointer, water problem;
AC Code:
#include <bits/stdc++.h>/*#include <vector> #include <iostream> #include <queue> #include <cmath> #include <map > #include <cstring> #include <algorithm> #include <cstdio>*/using namespacestd;#definefor (i,j,n) for (int i=j;i<=n;i++)#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong Longll;template<classT>voidRead (t&num) { CharCH;BOOLf=false; for(Ch=getchar (); ch<'0'|| Ch>'9'; f= ch=='-', ch=GetChar ()); for(num=0; ch>='0'&&ch<='9'; num=num*Ten+ch-'0', ch=GetChar ()); F&& (num=-num);}intstk[ -], Tp;template<classT> Inlinevoidprint (T p) {if(!p) {Puts ("0");return; } while(p) stk[++ TP] = p%Ten, p/=Ten; while(TP) Putchar (stk[tp--] +'0'); Putchar ('\ n');}ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);ConstLL inf=1e18;Const intn=2e5+Ten;Const intmaxn=1005;Const Doubleeps=1e-Ten;intA[n],sum[n];intMain () {intn,s; while(cin>>n>>s) {sum[0]=0; For (I,1, n) read (A[i]), sum[i]=sum[i-1]+A[i]; intL=1, r=1; intans=2*N; For (I,1, N) {L=i-1; while(sum[r]-sum[l]<s&&r<=n) r++; if(r<=n) Ans=min (ans,r-l); } if(ans<=n) cout<<ans<<"\ n"; Elsecout<<"0"<<"\ n"; } return 0;}
LA-2678 (ruler)