1 solutions

  • 0
    @ 2025-3-3 16:24:11

    C++ :

    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int n,m;
    int s,e;
    int tot=0;
    int ans=0;
    int h[250000]={0};
    
    char ch;
    int ret;
    int qin()
    {
    	ret=0;
    	while(ch=getchar(),!isdigit(ch));
    	while(ret=ret*10+ch-'0',ch=getchar(),isdigit(ch));
    	return ret;
    }
    
    void work()
    {
    	s=1;
    	e=0;
    	tot=0;
    	ans=0;
    	for(int i=1;i<=n;++i)
    	{
    		e++;
    		h[i]=qin();
    		tot+=h[i];
    		while(tot>=m)
    		{
    			if(ans==0||e-s+1<ans)
    			{
    				ans=e-s+1;
    			}
    			tot-=h[s];
    			s++;
    		}
    	}
    	printf("%d",ans);
    }
    
    int main()
    {
        scanf("%d%d",&n,&m);
        work();
        while(scanf("%d%d",&n,&m)!=EOF)
        {
    		printf("\n");
    		work();
    	}
        return 0;
    }
    
    • 1

    Information

    ID
    10047
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By