Source Code
#include <stdio.h>

int main()
{
    int n,k,p=0,min=99999,sum=0,max=0;
    scanf("%d%d",&n,&k);
    int a[n];
    for (int i=0 ; i<n ; i++)
    {
        scanf("%d",&a[i]);
        max+=a[i];
    }
    printf("\nProcessing...\n");
    
    
    
    while (p<n)
    {
        
        sum=max;
        for (int i=0; (p + (i*k))<n ; i++)
        {
            sum -= a[(p + (i*k))];
        }
        if (sum<min) 
        {
            min=sum;
        }
        p++;
        
    }
    printf("%d",min);
    
    
    return 0;
}
Copy
Offer Abu Jbarah
GNU G++17
3 ms
328 KB
Wrong Answer