1 solutions

  • 0
    @ 2024-11-29 14:21:22
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+9;
    int s[N];
    
    int main()
    {
    	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	
    	int n,m;cin>>n>>m;
    	for(int i=1;i<=n;++i)cin>>s[i];
    	if(m==0)
    	{
    		cout<<0;
    		return 0;
    	}
    	else
    	{
    		int cnt=0;
    	int min_val=0x3f3f3f3f;
    	int sum=0;
    	for(int i=1;i<=n;++i)
    	{
    		sum=s[i];
    		cnt=1;
    		for(int j=i+1;j<=n;++j)
    		{
    			if(cnt!=m)
    			{
    				sum+=s[j];
    				cnt++;
    			}
    			if(cnt==m)
    			{
    				min_val=min(min_val,sum);
    				break;
    			}
    		}
    	}
    	cout<<min_val;
    	}
    	return 0;
    }
    
    
    • 1

    Information

    ID
    3863
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    8
    Accepted
    1
    Uploaded By