Source Code
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    int n,k;
    long long int totalsum=0,sum=0,m=0;
    cin>>n>>k;
    vector<int>v(n);
    for(auto &i : v)
    {
    cin>>i;
    totalsum+=i;
    }
    for(int i = 0 ;i<n;i++)
    {
        int i1=i;
        while(i1<=n-1)
        {
            sum+=v[i1];
            i1+=k;
        }
        m=max(m,sum);
        sum=0;
    }
    cout<<totalsum-m;
}
Copy
Offer moathhamudah
GNU G++17
32 ms
1.0 MB
Accepted