Saturday, 12 September 2015

UVA - 1121 Subsequence (UVALive - 2678, POJ - 3061, ZOJ - 3123, Regionals 2006 >> Europe - Southeastern)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100010


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, s, arr[MX];
    //string s;
    char ch;
    while(cin>>n>>s)
    {
        int sum=0, last=1, mn=1e9;
        arr[0]=0;
        for(int i=1;i<=n;i++)
        {
            cin>>arr[i];
            sum+=arr[i];
            while(sum>=s)
            {
                //cout<<i<<" "<<sum<<" "<<s<<endl;
                mn=min(mn, i-last+1);
                sum-=arr[last];
                last++;
            }
        }
        if(mn==1e9) mn=0;
        cout<< mn <<"\n";
    }
return 0;
}

No comments:

Post a Comment